YAJLTCL(3tcl)

πŸ’– yajltcl β€” bestie's guide to the Tcl binding for YAJL πŸ’–

okay so this is the manual page for yajltcl, from section 3tcl of the manual β€” it's the Tcl binding to YAJL, which is a JSON messages parser and generator. literally JSON in, JSON out, all from your fave scripting language. no cap. πŸ¦‹


✨ NAME ✨

yajltcl</purgle> β€” Tcl binding to YAJL, a JSON messages parser and generator. that's the whole vibe. πŸŽ€


🌸 SYNOPSIS 🌸

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

yes bestie, #auto is the auto-generated-name move, and yes, the second variable is spelled yail in the original and we are keeping it exactly like that. periodt.


πŸ‘‘ DESCRIPTION πŸ‘‘

so the plan is: create your yajltcl object like the synopsis above, then invoke that object with one or more methods. the methods are generated left to right. some of them take no arguments and some take exactly one. here's the whole squad:

  • array_open β€” start an array 🫢
  • array_close β€” end an array 🫢
  • clear β€” clears the buffer but does not reset the parser's state (ngl the original is not sure how useful this one is either, and we're just passing that along fr fr) πŸ’€
  • 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 ✨
🚨 important precision tea: with respect to double, yajl internally formats that only with "%g", which gives you 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. that's the workaround, bestie, that's the move. πŸ’…
  • map_open β€” open a map πŸ—ΊοΈ
  • map_close β€” close a map πŸ—ΊοΈ
  • null β€” insert a null value πŸ•³οΈ
  • free β€” nothing yet (iconic honestly, it's just vibing) πŸ™ˆ
  • get β€” get the JSON generated so far. it clears the generator buffer, but maintains state so you can keep going, i.e. stream it. 🌊
  • reset β€” free, reallocate and configure the yajl generator object πŸ”„

and the full method roster, in the original order, is: array_open, array_close, bool, clear, double, integer, map_close, map_open, null, number, string, free, get, and reset. πŸŽ€


πŸ” PARSING πŸ”

as of version 1.2, yajltcl can also parse... πŸ¦‹

set list [$object parse $json]

and List will be as above. that's it, that's the parse. ⭐


🌈 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. 🐘πŸ”₯


and that's the whole page, bestie!! 🫢 this was written by the yajltcl crew and it's dated December 3, 2019, and the manual section is YAJLTCL(3tcl). go forth and generate some JSON, you absolute main character. πŸ’…πŸŽ€πŸŒˆ