Home > cson

cson

Cson is a project mainly written in C++ and C, based on the View license.

A Json-like data format: C++ and Haskell libraries

CSON library

The CSON Library

This is a parsing and lookup library for a data definition language - Cson. This may be how C syntax would define literals if it could define more things as literals. It started as the Javascript Object Notation Language JSON, but since I found JSON syntax somewhat awkward, shifting it in the direction of C seemed useful.

One can define values for structures with named fields, lists, and simple literals - numbers, strings, booleans and null. The syntax is specified in bnfc/Json.cf, using the bnfc language, and documented in bnfc/Json.pdf (which is produced by make bnfc).

The library provides simple lookup methods, akin to Xpath for XML. Using these, one can extract the value (scalar or array) of any component inside a CSON data structure, named as a path (list) of field names.

Some example data files are provided in examples/, and the test file test-get-path.cc, compiled to get-path, provides usage examples.

Example

This is example file examples/data-nested.cjs, and several lookups from it using get-path.
{   a = 1,
    b = 2,
    c = [ {x={aa=1, ab=4}, y=2},
      {x={aa=3, ab=8}, y=12}
     ],
    d = { a = 23, b = 25 }
    e = [ 1, 2, 3, 4 ]
}
$ ./get-path d b < examples/data-nested.cjs 
scalar:25
$ ./get-path c  < examples/data-nested.cjs 
list:
(1,4,2)
(3,8,12)
$


Subversion $Id: README.html 773 2008-03-30 12:56:38Z sasho $