Parse and serialize JSON

Introduction

This example shows how to use the builtin json module to parse and serialize JSON Objects and Arrays.

If you have any questions please contact us at support@interfaceware.com.

Using the Code [top]

  • Import the Parse and serialize JSON channel from the Builtin: Iguana Protocols repository
  • Experiment with the code to find out how it works
  • Then add the module(s) to your Translator project
  • Adapt the code to your own requirements
  • Use json.parse{} to parse JSON Objects or Arrays
  • Use json.serialize{} to serialize a table into a JSON Object or Array
  • Interactive scripting help is included for this module

This is the github code for the main module:

The example1.lua code uses simple XML to demonstrate parsing and serialization:

The other two local files use a more realistic demographic example, example2.lua uses a JSON object and example3.lua uses a JSON table.

How it works [top]

The code uses json.parse{} to parse both a JSON Object and a JSON Array into two tables. It then uses json.serialize{} to serialize the tables into a JSON Object and Array. You can inspect the annotations to see how this works.

The code is broken into three local files: The first example (example1.lua) uses a very simple XML example, the second and third examples (example2.lua and example3.lua) use a more realistic demographic example.

More information [top]