Dehydrate (serialize) as JSON

Added by iNTERFACEWARE

How to dehydrate (serialize) raw JSON data, this can be useful for storing in a databases

Source Code
 function main(Data)   
  -- serialize data as JSON
   
   -- this is the original JSON data:
   -- "{'int_test': 1.23, 'string_test':'a', 'boolean_test' : true}"
   
   -- JSON data as a Lua table
   local JT = {['int_test']=1.23, ['string_test']='a', ['boolean_test']=true}

   -- serialize the Lua table into JSON
   local JS = json.serialize{data=JT}   
   --> '{ "int_test": 1.230000, "boolean_test": true, "string_test": "a" }'
   -- notice the changed order and added decimal places for int_test
   -- when compared to our original JSON data:
   -- "{'int_test': 1.23, 'string_test':'a', 'boolean_test' : true}"
   
   -- parse the JSON string back to a Lua table for comparison
   local JT = json.parse{data=JS}
   --> {['int_test']=1.230000, ['boolean_test']=true, ['string_test']='a'}
   -- again notice the changed order and added decimal places for int_test
   -- when compared to our original table:
   -- {['int_test']=1.23, ['string_test']='a', ['boolean_test']=true}
end
Description
How to dehydrate (serialize) raw JSON data, this can be useful for storing in a databases