Home  Contents

Introduction

JSON Core4 Lua Commands

DESCRIPTION

Overview

JSON, or JavaScript Object Notation, is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. It is used primarily to transmit data between a server and web application, as an alternative to XML.(From Wikipedia)

JSON maps relatively well onto Lua tables, with two issues.

  • Mapping JSON null to Lua nil is not straightforward. When assigning nil to a table entry, the entry just disappears.
  • Lua does not preserve the order of items in a table.

To fix these, the JSON implementation presented here requires the use of a JSON schema when encoding a table into JSON. The schema ensures that null entries are preserved and that the order of items is as required by the schema.

Functions

table.toJson() encodes a lua table into a JSON string.

table.fromJson() decodes a JSON string into a lua table.

table.fromJsonSchema() decodes a JSON schema specification for use with table.toJson().