json(n)
β¨ json(n) β¨
okay bestie, gather round π this is the manual page for json, the JSON parser in Tcl land. Yes it's a Tcl thing. Yes it's cute. Let's go π¦
NAME
json β it's a JSON parser, that's the whole vibe π
SYNOPSIS
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 literally a simple Tcl-only library for parsing the JSON data exchange format β that's http://www.json.org/ β exactly as specified in RFC 4627 over at http://www.ietf.org/rfc/rfc4627.txt. no cap πΈ
and here's the tea: there is some ambiguity when parsing JSON, because JSON carries type information that Tcl's conversion just does not maintain. it's giving "we lost the receipts" π
the json package hands you back your data as a Tcl dict. and heads up β you need either the dict package or Tcl 8.5 for any of this to work. non-negotiable bestie π«Ά
COMMANDS
::json::json2dict txtβ parses JSON formatted texttxtinto a Tcl dict and returns that value. π
lowkey important: if txt contains more than one JSON entity, only the first one comes back. the rest just... don't get an invite π
::json::many-json2dict txt ?max?β parses JSON formatted texttxtthat contains multiple JSON entities, into a list of dictionaries, and returns that list. iconic β¨
if max is specified, exactly that many entities are extracted from txt. by default the command tries 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. don't do it. fr fr π
EXAMPLES
first up: a JSON array converted to Tcl. a JSON array comes back as a single item with multiple elements π
[
{
"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}
and now a JSON object converted to Tcl. a JSON object comes back as a multi-element list β which is, you guessed it, a dict π
{
"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
wanna write json instead of parsing it? different girl, different page β go see package json::write. π
BUGS, IDEAS, FEEDBACK
ngl, this document β and the package it describes β will undoubtedly contain bugs and other problems. it's giving "we're all just doing our best" π
please report them in the category json of the Tcllib Trackers: http://core.tcl.tk/tcllib/reportlist
also pls pls pls report any ideas you have for enhancements to either the package and/or the documentation. we love ideas here π«Άβ¨
if you're proposing code changes, send unified diffs β that's the output of diff -u. periodt.
π one more thing: 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. iykyk.
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
and that's the whole page bestie π this one ships with tcllib, version 1.3.6, and it's filed under the manual name json(n). slay, go parse something gorgeous β¨ππ
π¦ 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) 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