1json(n) JSON parser json(n)
2
3
4
5______________________________________________________________________________
6
8 json - JSON parser
9
11 package require Tcl 8.4
12
13 package require json ?1.0?
14
15 ::json::json2dict txt
16
17_________________________________________________________________
18
20 The json package provides a simple Tcl-only library for parsing the
21 JSON http://www.json.org/ data exchange format as specified in RFC 4627
22 http://www.ietf.org/rfc/rfc4627.txt. There is some ambiguity in pars‐
23 ing JSON because JSON has type information that is not maintained by
24 the Tcl conversion. The json package returns data as a Tcl dict.
25 Either the dict package or Tcl 8.5 is required for use.
26
28 ::json::json2dict txt
29 Parse JSON formatted text txt into a Tcl dict and return the
30 value.
31
33 An example of a JSON array converted to Tcl. A JSON array is returned
34 as a single item with multiple elements.
35
36 [
37 {
38 "precision": "zip",
39 "Latitude": 37.7668,
40 "Longitude": -122.3959,
41 "Address": "",
42 "City": "SAN FRANCISCO",
43 "State": "CA",
44 "Zip": "94107",
45 "Country": "US"
46 },
47 {
48 "precision": "zip",
49 "Latitude": 37.371991,
50 "Longitude": -122.026020,
51 "Address": "",
52 "City": "SUNNYVALE",
53 "State": "CA",
54 "Zip": "94085",
55 "Country": "US"
56 }
57 ]
58 =>
59 {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}
60
61
62 An example of a JSON object converted to Tcl. A JSON object is
63 returned as a multi-element list (a dict).
64
65 {
66 "Image": {
67 "Width": 800,
68 "Height": 600,
69 "Title": "View from 15th Floor",
70 "Thumbnail": {
71 "Url": "http://www.example.com/image/481989943",
72 "Height": 125,
73 "Width": "100"
74 },
75 "IDs": [116, 943, 234, 38793]
76 }
77 }
78 =>
79 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}}
80
81
83 This document, and the package it describes, will undoubtedly contain
84 bugs and other problems. Please report such in the category json of
85 the Tcllib SF Trackers [http://source‐
86 forge.net/tracker/?group_id=12883]. Please also report any ideas for
87 enhancements you may have for either package and/or documentation.
88
90 data exchange, exchange format, javascript, json
91
93 Copyright (c) 2006 ActiveState Software Inc.
94
95
96
97
98json 1.0 json(n)