json::write(3tcl)
β¨ NAME β¨
json::write β making JSON, bestie π
πΈ 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 π¦
okay so the json::write package is literally a simple, Tcl-only library for generating text in the JSON data exchange format π β the one specified in RFC 4627 (yes the original spec, she's vintage, we love her). The URLs in question are http://www.json.org/ and http://www.ietf.org/rfc/rfc4627.txt if you wanna go read the lore iykyk.
Tcl-only means no weird external deps, just vibes and pure Tcl. Slay. β¨
π COMMANDS π
::json::write indentedβ no args, no drama. This one just tells you the current state of the indentation setting. A little peek, a little status check π::json::write indented flagβ this one and thealignedmethod are the ones that control the layout of the JSON the package spits out.- if this
flagis set (and it is by default, bestie), the package will break the generated JSON across lines and indent it according to its inner structure, with each key of an object chillin' on its own separate line π - if this
flagis not set, the whole JSON object gets written on a single line, with minimum spacing between all elements. Compact mode. Zero breathing room. periodt.
- if this
::json::write alignedβ the twin of the above. Returns the current state of the alignment setting. Status check, but make it aligned π«Ά::json::write aligned flagβ this one and theindentedmethod configure the layout of the JSON generated by the package.- if this
flagis set (default again, yes girl), the package makes sure the values for the keys in an object are vertically aligned with each other, for a cute little table effect. and to make that work it also implies thatindentedis set as well β they're a package deal fr fr π - if this
flagis not set, the output is formatted as per whateverindentedsays, with no attempt to align the values for object keys. Just raw formatting, no table glamour.
- if this
::json::write string sβ hands you the string s back, but properly quoted for JSON as the result. Escaping handled, you're welcome π::json::write array arg...β takes a whole series of JSON-formatted arguments and returns them as a properly formatted JSON array. One big iconic list πΈ::json::write array-strings arg...β the convenience variant ofarray, for when you can't be bothered. It assumes all the arguments are plain strings and formats them as JSON strings before passing them intoarray. Lazy girl math but correct π::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. Curly braces but make it fashion.::json::write object-strings key value...β the convenience variant ofobject. It assumes all the value arguments are plain strings and formats them as JSON strings before passing them intoobject. Same energy, less typing π
π RELATED π
Wanna go the other direction and parse json instead of writing it? See package json. Reader girlies, this one's for you π
π BUGS, IDEAS, FEEDBACK π
ngl this document, and the package it describes, will undoubtedly contain bugs and other problems. it's giving "we know". Please report such in the category json of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. And please also report any ideas for enhancements you may have for either the package and/or the documentation β we want the glow-up suggestions π«Άβ¨
When proposing code changes, please provide unified diffs, i.e. the output of diff -u. That's the love language here.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made 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. ok that's very specific but that's literally the instruction, no cap π
β KEYWORDS β
data exchange, exchange format, javascript, json
π CATEGORY π
CGI programming
π COPYRIGHT π
Copyright (c) 2009-2013,2022 Andreas Kupries <andreas_kupries@sourceforge.net>
and that's the whole page bestie!! this one's from tcllib, version 1.0.5, and it's the json::write(3tcl) page πβ¨ go make some JSON, you're gonna eat π
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- 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