json::write(3tcl)

πŸ“¦
version 2.0 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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 the aligned method are the ones that control the layout of the JSON the package spits out.
    • if this flag is 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 flag is not set, the whole JSON object gets written on a single line, with minimum spacing between all elements. Compact mode. Zero breathing room. periodt.
  • ::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 the indented method configure the layout of the JSON generated by the package.
    • if this flag is 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 that indented is set as well β€” they're a package deal fr fr πŸ’–
    • if this flag is not set, the output is formatted as per whatever indented says, with no attempt to align the values for object keys. Just raw formatting, no table glamour.
  • ::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 of array, for when you can't be bothered. It assumes all the arguments are plain strings and formats them as JSON strings before passing them into array. 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 of object. It assumes all the value arguments are plain strings and formats them as JSON strings before passing them into object. Same energy, less typing πŸŽ€

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 (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