json(3tcl)
π json β the JSON parser page, but make it cute π
okay bestie, so this is the json(3tcl) manual page β like, the JSON section of the Tcllib docs, and we're about to read it together. grab a boba, it's gonna be fun. π§β¨
π NAME π
json β JSON parser. that's it. that's the name. short, sweet, iconic. π
β¨ SYNOPSIS β¨
like, the whole vibe in one glance:
package require Tcl 8.5 9
package require json ?1.3.6?
::json::json2dict txt
::json::many-json2dict txt ?max?
πΈ DESCRIPTION πΈ
so the json package is a simple, Tcl-only library for parsing the JSON data exchange format β you know, the one at http://www.json.org/ β exactly as specified in RFC 4627 (http://www.ietf.org/rfc/rfc4627.txt). no C extensions, no drama, just Tcl doing its thing. π
now here's the tea: there's some ambiguity in parsing JSON, because JSON carries type information that Tcl's conversion justβ¦ doesn't keep. it's giving "we don't do types here." π« so the json package hands you back your data as a Tcl dict. and because of that, you need either the dict package or Tcl 8.5 to use it. no cap.
π¦ COMMANDS π¦
::json::json2dict txt
parses JSON-formatted text txt into a Tcl dict and returns that value. simple. clean. ate. β¨
- if
txtcontains more than one JSON entity, only the first one gets returned. that's it, bestie, the rest just sits there unread. π
::json::many-json2dict txt ?max?
parses JSON-formatted text txt that contains multiple JSON entities and returns them as a list of dictionaries. the more the merrier. π₯
- if
maxis specified, exactly that many entities get extracted fromtxt. - by default, the command will try to extract all of them β no limits, main character energy. π
- a value of
"max == 0"does not make sense and will cause the command to throw an error. so likeβ¦ don't. π
π EXAMPLES π
an example of a JSON array converted to Tcl π¦
a JSON array comes back as a single item with multiple elements. watch:
[
{
"precision": "zip",
"Latitude": 37.7668,
"Longitude": -122.3959,
"Address": "",
"City": "SAN FRANCISCO",
"State": "CA",
"Zip": "94107",
"Country": "US"
},
{
"precision": "zip",
"Latitude": 37.371991,
"Longitude": -122.026020,
"Address": "",
"City": "SUNNYVALE",
"State": "CA",
"Zip": "94085",
"Country": "US"
}
]
=>
{Country US Latitude 37.7668 precision zip State CA City {SAN FRANCISCO} Address {} Zip 94107 Longitude -122.3959} {Country US Latitude 37.371991 precision zip State CA City SUNNYVALE Address {} Zip 94085 Longitude -122.026020}
an example of a JSON object converted to Tcl π
a JSON object comes back as a multi-element list (a dict). periodt.
{
"Image": {
"Width": 800,
"Height": 600,
"Title": "View from 15th Floor",
"Thumbnail": {
"Url": "http://www.example.com/image/481989943",
"Height": 125,
"Width": "100"
},
"IDs": [116, 943, 234, 38793]
}
}
=>
Image {IDs {116 943 234 38793} Thumbnail {Width 100 Height 125 Url http://www.example.com/image/481989943} Width 800 Height 600 Title {View from 15th Floor}}
π RELATED π
if you wanna write JSON instead of parsing it, go look at the json::write package. different girl, different job. π
π BUGS, IDEAS, FEEDBACK π
ngl, this document and the package it describes will undoubtedly contain bugs and other problems. it's giving humble. please report them in the category json of the Tcllib Trackers here: http://core.tcl.tk/tcllib/reportlist. and if you have ideas for enhancements for the package and/or the documentation, send those too. we're listening. π«Ά
when you propose code changes, please provide unified diffs β i.e. the output of diff -u. that's the standard, bestie.
also important: attachments are strongly preferred over inlined patches. you make an attachment by going to the Edit form of the ticket immediately after creating it, and then using the left-most button in the secondary navigation bar. yep, that specific one. π―
β KEYWORDS β
data exchange, exchange format, javascript, json
πΈ CATEGORY πΈ
CGI programming
π COPYRIGHT π
Copyright (c) 2006 ActiveState Software Inc.
Copyright (c) 2009 Thomas Maeder, Glue Software Engineering AG
okay that's the whole page!! this was tcllib version 1.3.6, the json(3tcl) page, and that's the vibe check complete. go parse something gorgeous, bestie. πβ¨π¦π
π¦ 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) 2006 ActiveState Software Inc\&
- Copyright (c) 2009 Thomas Maeder, Glue Software Engineering AG
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms