Using JSON library in Codea

I have been trying to find and implement a library to decode JSON. After searching the discussions I saw a few people saying they have had success using dkjson. I have tried for a while now to get the dkjson module to work but need some help.

Currently I have a project with two tabs: one for the dkjson module and one a main where I am trying to implement it. The library says to import it using " json = require(“dkjson”) " in the regular Lua environment but I have yet to find how to properly call it in Codea.

How do you properly use this module?


Not sure about that module but I and several others use a simple JSON Library. Mine is from

Most likely, for yours, just remove the require line and add the file to your project.

That library seems to be better.
It still didn’t work at first, I learned that I couldn’t just get rid of the require lines. I had to change them so that:

local math = require(‘math’)
is now:
local math = _G.math

local string = require(“string”)
is now:
local string = _G.string

local table = require(“table”)
is now:
local table = _G.table

I’m not quite sure what this is doing so if someone can elaborate I’d love to know. Thanks for pointing me to that though!

Those lines would “require” or “import” the math, string and table function libraries into local table instances for improved access speed. require’ing the same library over and over is ok as the require function checks to see if the table is already loaded and if so returns a reference to it instead.

What your doing is replacing the require with local references to the same tables that have already been loaded and stored in the global table (_G) which is basically the same thing (or at least achieves the same results - stores a local reference for increased access speed)

TechDojo - That helps clear things up for me, thanks for that explanation.

Honestly, remove those lines - those libs are already compiled into Codea.

can some one provide a working example that encodes/decodes json ?!? i hear allot of talk about it but haven’t seen a single example on these forms :frowning:

dkjson, simply include it in a tab then json.encode() json.decode()