dkjson
Update of "dkjson"
Not logged in

Chisel is closing down. This repository can be found under the new URL dkolf.de/src/dkjson-lua.fsl/.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: 8ccb2aac39234e45768169b2ca8819a51442af1e
Page Name:dkjson
Date: 2013-04-14 19:06:55
Original User: dhkolf
Parent: f64bd3541fe7d065c6fb558df710a70f6d3ac435
Content

JSON Module for Lua

Introduction

This is a JSON module written in Lua without any dependencies to other external libraries. It supports UTF-8.

Download

Usage

The full documentation is available here in the wiki or as Markdown text in the source file.

Examples

Encoding


local json = require ("dkjson")

local tbl = {
  animals = { "dog", "cat", "aardvark" },
  instruments = { "violin", "trombone", "theremin" },
  bugs = json.null,
  trees = nil
}

local str = json.encode (tbl, { indent = true })

print (str)

Output


{
  "bugs":null,
  "instruments":["violin","trombone","theremin"],
  "animals":["dog","cat","aardvark"]
}

Decoding


local json = require ("dkjson")

local str = [[
{
  "numbers": [ 2, 3, -20.23e+2, -4 ],
  "currency": "\u20AC"
}
]]

local obj, pos, err = json.decode (str, 1, nil)
if err then
  print ("Error:", err)
else
  print ("currency", obj.currency)
  for i = 1,#obj.numbers do
    print (i, obj.numbers[i])
  end
end

Output

currency	€
1	2
2	3
3	-2023
4	-4

Versions

Version 2.3 (2013-04-14)

Changes since version 2.2:

Version 1.2 (2013-04-14)

Changes since version 1.1:

Version 2.2 (2012-04-28)

Changes since version 2.1:

Version 2.1 (2011-07-08)

Changes since version 2.0:

Version 1.1 (2011-07-08)

Changes since version 1.0:

Version 2.0 (2011-05-30)

Changes since version 1.0:

Version 1.0

Initial version, released 2010-08-28.