The JSON library now comes pre-installed

Share on Facebook0Share on Google+2Tweet about this on TwitterShare on LinkedIn0

The JSON library that we’ve been shipping in our sample code (e.g. Facebook) is now an official part of the Corona core. The really great thing about this library is that it makes serializing/deserializing Lua tables a no-brainer.

[cc lang=”lua”]
local json = require “json”

— Lua script:
local t = {
[“name1”] = “value1”,
[“name2”] = {1, false, true, 23.54, “a 21 string”},
name3 = json.null()

local json = json.encode (t)
print (json)
–> {“name1″:”value1″,”name3″:null,”name2″:[1,false,true,23.54,”a u0015 string”]}

local t = json.decode(json)
–> 23.54

As long as you don’t have userdata or functions or cycles (tables with child values that reference a parent table), you’re good to go.

For those of you who don’t speak SQL in your sleep or think the sqlite library is too heavyweight, it’s a great alternative that’s perfect for doing simple persistent storage.

Share on Facebook0Share on Google+2Tweet about this on TwitterShare on LinkedIn0

This entry has 7 replies

  1. Leo says:


  2. Shawn says:


  3. Maicol R. says:


    How to load external json?

    local and external json files or json output…


  4. Jonathan Beebe says:

    @Maicol R: Stay tuned for an upcoming tutorial on using this integrated JSON library–to include using it in conjunction with external JSON text files.

  5. Josep Alemany says:

    Very interesting!

    Could you write a sample to use it with an http request???

    Thanks in advance,

    Josep Alemany

  6. leo says:

    How to use json with unicode

  7. Lenny says:

    I got a Json String from a mysql Database with a address field where an \u00E4 ( a geman ä ) is responsed but i want to change it to an ä.

    I used string.gsub to replace \u00E4 to an ä but it doesn’t work.

    how can I solve this problem. If I put the database field into an local … or an array and print it than i always get ….?….. that means an ? instead of the \u00E4.

    it is very urgent so i would be pleased of any solution

    Thanks in advance