Scroll to navigation

YAJLTCL(3tcl) YAJLTCL(3tcl)

NAME

yajltcl - Tcl binding to YAJL, a JSON messages parser and generator

SYNOPSIS

package require yajltcl
set yajl [yajltcl <cmdname>] or
set yail [yajltcl #auto]

DESCRIPTION

Create your yajltcl object as above then invoke the object with one or more methods. They are generated left to right. Some have no arguments and some have one. The methods are: array_open, array_close, bool, clear, double, integer, map_close, map_open, null, number, string, free, get, and reset


array_open - start an array
array_close - end an array
clear - clears the buffer but doesn't reset the parser's state (not sure how useful this is)
bool - add a boolean, value follows
double - add a double precision floating point value, value follows
integer - add an integer value, value follows
number - add a numeric value, value follows

Note that with respect to "double" yajl internally formats that only with "%g", providing six digits of precision, and this is not currently configurable via YAJL. If you need higher precision, use "format" or equivalent, coupled with yajltcl's "number" method.



map_open - open a map
map_close - close a map
null - insert a null value
free - nothing yet
get - get the JSON generated so far. clears the generator buffer. maintains state so you can keep going, i.e. stream it.
reset - free, reallocate and configure the yajl generator object

PARSING

As of version 1.2, yajltcl can also parse... set list [$object parse $json] List will be as above.

YAJLTCL LIBRARY ROUTINES

add_array_to_json jsonObject arrayName - append a Tcl array into the specified json object by doing a JSON map open and then storing the array as key-value pairs and then doing a map close. Example usage:


set json [yajl create #auto]
add_array_to_json $json array
puts [$json get]
rename $json ""



array_to_json arrayName - return the contents of the array as JSON text
add_pgresult_tuples_to_json jsonObject res
- append a JSON array of JSON objects of a Postgres result,
one array entry per tuple in the result, with the non-null
values set in each row object.
pg_select_to_json conn sql - given a postgres connection handle and a sql select statement,
perform the select and return the results of the select as JSON text.

December 3 2019