---
name: "yajltcl"
section: "3tcl"
platform: "linux"
package: "tcl-yajltcl"
version: "1.8.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/yajltcl"
---

# yajltcl(3tcl)

Tcl binding to YAJL, a JSON messages parser and generator

## 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.
