1json::write(n)                       JSON                       json::write(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       json::write - JSON generation
9

SYNOPSIS

11       package require Tcl  8.5
12
13       package require json::write  ?1.0.4?
14
15       ::json::write indented
16
17       ::json::write indented flag
18
19       ::json::write aligned
20
21       ::json::write aligned flag
22
23       ::json::write string s
24
25       ::json::write array arg...
26
27       ::json::write array-strings arg...
28
29       ::json::write object key value...
30
31       ::json::write object-strings key value...
32
33______________________________________________________________________________
34

DESCRIPTION

36       The  json::write package provides a simple Tcl-only library for genera‐
37       tion of text in the JSON http://www.json.org/ data exchange  format  as
38       specified in RFC 4627 http://www.ietf.org/rfc/rfc4627.txt.
39

COMMANDS

41       ::json::write indented
42              This  method  returns  the current state of the indentation set‐
43              ting.
44
45       ::json::write indented flag
46              This and the method aligned configure the  layout  of  the  JSON
47              generated by the package.
48
49              If  this flag is set (default) the package will break the gener‐
50              ated JSON code across lines and indent it according to its inner
51              structure, with each key of an object on a separate line.
52
53              If  this  flag is not set, the whole JSON object will be written
54              on a single line, with minimum spacing between all elements.
55
56       ::json::write aligned
57              This method returns the current state of the alignment setting.
58
59       ::json::write aligned flag
60              This and the method indented configure the layout  of  the  JSON
61              generated by the package.
62
63              If  this flag is set (default) the package ensures that the val‐
64              ues for the keys in an object are vertically aligned  with  each
65              other,  for a nice table effect. To make this work this also im‐
66              plies that indented is set as well.
67
68              If this flag is not set, the output  is  formatted  as  per  the
69              value of indented, without trying to align the values for object
70              keys.
71
72       ::json::write string s
73              This method takes the string s and returns  it  properly  quoted
74              for JSON as its result.
75
76       ::json::write array arg...
77              This  method  takes a series of JSON formatted arguments and re‐
78              turns them as a properly formatted JSON array as its result.
79
80       ::json::write array-strings arg...
81              This is a convenience variant of array. It assumes that all  ar‐
82              guments  are  plain strings and formats them as JSON strings be‐
83              fore passing them into the array.
84
85       ::json::write object key value...
86              This method takes a series of key/value  arguments,  the  values
87              already  formatted for JSON, and returns them as a properly for‐
88              matted JSON object as its result, with  the  keys  formatted  as
89              JSON strings.
90
91       ::json::write object-strings key value...
92              This  is  a  convenience  variant of object. It assumes that all
93              value arguments are plain  strings  and  formats  them  as  JSON
94              strings before passing them into the object.
95
97       To parse json, instead of writing it, see package json.
98

BUGS, IDEAS, FEEDBACK

100       This  document,  and the package it describes, will undoubtedly contain
101       bugs and other problems.  Please report such in the  category  json  of
102       the  Tcllib  Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please
103       also report any ideas for enhancements you may have for either  package
104       and/or documentation.
105
106       When proposing code changes, please provide unified diffs, i.e the out‐
107       put of diff -u.
108
109       Note further that  attachments  are  strongly  preferred  over  inlined
110       patches.  Attachments  can  be  made  by  going to the Edit form of the
111       ticket immediately after its creation, and  then  using  the  left-most
112       button in the secondary navigation bar.
113

KEYWORDS

115       data exchange, exchange format, javascript, json
116

CATEGORY

118       CGI programming
119
121       Copyright (c) 2009-2013,2022 Andreas Kupries <andreas_kupries@sourceforge.net>
122
123
124
125
126tcllib                               1.0.4                      json::write(n)
Impressum