Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

JSON is a lightweight, plain text data format. It’s become a standard that is widely used across many industries, even healthcare.

Its simple structure makes it a good example to review some key Lua and Translator concepts.

Lets start!

 Add Sample Data by importing the provided sample file

Use the following file:

See Sample Data for how to add sample files to a project.

 Use the Annotation Window to view your sample data in the String Viewing Window as Escaped Text.

Now we can see our sample data passed to main by looking at the Annotation Windows. If we click on the sample data in the annotations, we can view it using The string viewing window in Escaped Text view.

Notice, how the JSON object is formatted. Each line ends with a newline “\n” character. We can use this to parse and process the JSON.

 Use string.split() to parse the JSON sample data

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

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 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.

 Parse the JSON sample data using json.parse{data=Data}
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.

 Click here to expand...
 Click here to expand...

 Serialize the table as a JSON string using json.serialize{data=Data}
local string = json.serialize{data=patient}
trace(string)

  • No labels