json::write(n)
π json::write(n) β the manual page, but make it a group chat π
okay bestie, so json::write is a Tcl package (it lives in tcllib) and it's literally your girl for making JSON. writing it, not reading it. if you wanna read JSON you're in the wrong doc, we'll get to that. sit down, hydrate, let's go β¨
πΈ NAME πΈ
json::write β JSON generation π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require json::write ?1.0.5?
::json::write indented
::json::write indented flag
::json::write aligned
::json::write aligned flag
::json::write string s
::json::write array arg...
::json::write array-strings arg...
::json::write object key value...
::json::write object-strings key value...
π¦ DESCRIPTION π¦
so like. the json::write package is a whole Tcl-only library (no weird dependencies, we love that for her π«Ά) whose entire job is generating text in the JSON data exchange format β the one at http://www.json.org/ β as specified in RFC 4627 http://www.ietf.org/rfc/rfc4627.txt. it makes the JSON. that's the gig. iconic honestly.
π COMMANDS π
π ::json::write indented
she returns the current state of the indentation setting. that's it, that's the whole command. vibe check on indentation.
π ::json::write indented flag
this one and aligned are the duo that configure the layout of the JSON this package spits out. the aesthetic committee, basically.
- if this flag is set (it's the default btw β¨) the package will break the generated JSON across lines and indent it according to its inner structure, with each key of an object on a separate line. readable. pretty. main character energy.
- if this flag is not set, the whole JSON object gets written on a single line, with minimum spacing between all elements. compact mode. no crumbs.
π ::json::write aligned
returns the current state of the alignment setting. yes, there's a separate one for alignment, keep up bestie π
π ::json::write aligned flag
this and indented are the layout besties, same deal as above.
- if this flag is set (default again, we stay consistent π) the package makes sure the values for the keys in an object are vertically aligned with each other, for a nice table effect. and to make that work it also implies that
indentedis set too. package said "we're doing both, no debate." - if this flag is not set, the output is formatted as per the value of
indented, without trying to align the values for object keys. so it's still pretty, just not table pretty.
π ::json::write string s
takes the string s and returns it properly quoted for JSON as its result. escaping? handled. you're welcome.
π ::json::write array arg...
takes a series of JSON formatted arguments and returns them as a properly formatted JSON array. note: already formatted, she's not doing the work for you here.
π ::json::write array-strings arg...
a convenience variant of array. it assumes all the arguments are plain strings and formats them as JSON strings before passing them into array. lazy-girl-friendly. no cap.
π§ ::json::write object key value...
takes a series of key/value arguments, where the values are already formatted for JSON, and returns them as a properly formatted JSON object, with the keys formatted as JSON strings. keys get the string treatment, values you brought yourself.
π§ ::json::write object-strings key value...
a convenience variant of object. it assumes all the value arguments are plain strings and formats them as JSON strings before passing them into object. so like, the strings-y sibling. slay.
π RELATED π
wanna go the other direction and parse json instead of writing it? go see the package json. that's her. different girl, same family.
π BUGS, IDEAS, FEEDBACK π
ngl, this document and the package it describes will undoubtedly contain bugs and other problems. like, for sure. please report them in the category json of the Tcllib Trackers: http://core.tcl.tk/tcllib/reportlist. and please also drop any ideas you have for enhancements to either the package and/or the documentation. we wanna hear it fr fr.
when you're proposing code changes, please provide unified diffs, i.e. the output of diff -u. that's the format. don't freestyle it.
also note, and this is important, attachments are strongly preferred over inlined patches. you make an attachment by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. that's the way. iykyk.
β KEYWORDS β
data exchange, exchange format, javascript, json
πΈ CATEGORY πΈ
CGI programming
π«Ά COPYRIGHT π«Ά
Copyright (c) 2009-2013,2022 Andreas Kupries <andreas_kupries@sourceforge.net>
okay that's the whole page bestie, you ate π
this little beauty ships as part of tcllib, version 1.0.5 β go forth and generate some JSON, mwah πβ¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2009-2013,2022 Andreas Kupries <andreas_kupries@sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms