Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleUse string.split() to parse the JSON sample data

You can use String:split() to split the function on (“\n”):

Code Block
languagelua
local List = Data:split("\n")
trace(List)

By Using trace() function, we can click on the List in the annotations and see the following:

This string is split into a Lua table with individual lines as list you can now begin to process. This is great... but with Iguana, we’ve made it a little easier to efficiently parse and process JSON.

Expand
titleParse the JSON sample data using json.parse{data=Data}
Code Block
languagelua
local patient = json.parse{data=Data}

JSON objects are parsed into Lua tables as dictionaries with key-value pairs. You can see this clearly in the Annotation Window.

...

Expand
titleSerialize the table as a JSON string using json.serialize{data=Data}
Code Block
languagelua
local string = json.serialize{data=patient}
trace(string)