read.proc
Read a JSON string and map its data to a set or String and Table objects
representing JSON lists and objects respectively. Regardless of how many
of these are created, the ID of the root object will be stored in the
.return
internal variable.
Read a JSON pair.
Read a JSON value.
Read the next token in a string, and optionally consume it. The token can
be specified either as a literal string or as a regular expression. The
choice between these is done automatically by the procedure: a string is
considered a regular expression pattern if it is enclosed in slashes (/
) and
contains at least one non-slash character in between. All other strings will
be interpreted as literals.
The procedure will automatically remove any whitespace characters at the beginning of the input string.
Cleanly abort parsing a JSON string.
write.proc
Executed with a selected Table object (ideally, one prepared by @hash
and
populated by a procedure such as @keyval
), or a Strings object (likewise
prepared by @array
and populated by procedures like @push
), this
procedure prints the contents of those objects as a JSON serialised string
to the Info window (or STDOUT).
The values in those objects can be marked as the reference to another
existing Table (ie. object) or Strings (ie. list) by using the @keyref
procedure to append the reference as a value in a Table, or the @pushref
or @unshiftref
procedures to do so with lists.
Values are marked as references by being suffixed with an “ID carat”.
By default, this is set to the hash character (#), but this can be changed
(see below). When a value is identified as a reference, an object-specific
procedure is called to handle that object: if the reference is to a “Table”
object the procedure called is @table_to_json
; if the object is a
“PointProcess” object, the procedure called will be @pointprocess_to_json
;
and so on.
The procedures for Tables (hashes) and Strings (lists) are provided by this
file, but the user is free to implement procedures for other objects if
needed. It is recommended, however, that those procedures use the
procedures in hash.proc
and array.proc
to populate the appropriate
Table or Strings objects, and then run @write_json
to print them. The
@write_json
procedure can be safely called recursively, to handle these
cases.
For algorithmic efficiency, when a Table has multiple rows it will be
treated by @write_json
as a list of similar objects. This avoids the overhead
involved in having to create multiple Tables with similarly named columns,
and a Strings object to hold their references.
The specific formatting of the JSON output is controlled by a series of global variables. in particular:
json.indent$
: the string to use for one level of indentation if output
is not minified (defaults to tab$
)json.minify
: if true, eliminate all non-meaningful whitespace from
outputjson.precision
: the maximum precision of numeric valuesjson.undef$
: the string to use for undefined values (defaults to “null”
as a bare string, native to JSON)json.empty_is_undef
: if true, empty values are printed as null values;
otherwise they are printed as empty stringsjson.ignore_undef
: if true, null values are not printedjson.empty_lists
: if true, Tables are printed as lists, regardless of
the number of rowsjson.id_carat$
: the string suffix used to identify a value as an object
referenceWorks in the same way as @keyval
, but automatically marks the stored
value as the reference to an existing object.
Works in the same way as @push
, but automatically marks the stored value
as the reference to an existing object.
Works in the same way as @unshift
, but automatically marks the stored
value as the reference to an existing object.
This procedure handles the printing of Table objects as a JSON string. The
procedure expects a Table formatted like those generated by the procedures
in hash.proc
.
This procedure handles the printing of Strings objects as a JSON string.
The procedure expects a Strings object, ideally one generated by the
procedures in [array.proc
][strutis].
Handle the beginning of a JSON object or list.
Handle the end of a JSON object or list.
Prints a JSON key.
Prints a JSON numeric value.
Prints a JSON string value.
Print a JSON string
Increase indentation of JSON output
Decrease indentation of JSON output
json.proc
Remove the current top level object representation, and all internally linked references.
Called internally to remove a hash Table object, and all its internal references.
Called internally to remove a array Strings object, and all its internal references.
Internal procedure to check whether a given value stores a reference. The check
is done by matching agains the current value of the json.id_carat$
variable.
hash.proc
In the same way that the array.proc
file in the strutils
plugin provides
array support using Strings objects as a substitute, these procdures provide
conveniency procedures for treating Table objects as hashes.
Creates a Table object which contains a subset of the strings
of an original Strings object. Search query is a literal string. For
regular expression matching, use
@extractStrings_regex
.
The new Strings object will be selected after execution.
Insert a numeric key / value pair to the first row in the current hash-like Table.
Insert a string key / value pair to the first row in the current hash-like Table.
Delete a key from the current hash-like Table. All the values in that column will be lost.
vars.proc
This file encapsulates all the variables used for encoding and decoding JSON. The variables listed below are shown with their default values. Modifying these can have unexpected consequences.
json.string$
:
“””([^””\]|\[””\/bfnrt]|\u[0-9a-fA-F]{4})*”””
json.number$
:
“[-+]?([1-9][0-9]*(.[0-9]+)?|0(.[0-9]+)?)([eE][-+]?[0-9]+)?”
json.true$
:
“true”
json.false$
:
“false”
json.null$
:
“null”
json.object_start$
:
“{“
json.object_end$
:
“}”
json.array_start$
:
“[”
json.array_end$
:
“]”
json.max_depth
:
undefined
json.indent$
:
tab$
json.minify
:
0
json.precision
:
undefined
json.undef$
:
“null”
json.empty_is_undef
:
0
json.ignore_undef
:
0
json.empty_lists
:
0
json.id_carat$
:
“#”