File json.icn

Summary


 json.icn - JSON support library

 Authors: Gigi Young, Clinton Jeffery

 This library is intended to support conversion of Unicon values
 to and from JSON format, suitable for storage or transmission.

Classes:
ErrorHandler

Procedures:
_dectohex, _octtohex, _utoj, json_parser, json_scanner, jsonify_string, jtou, jtouf, jtous, main, parse_array, parse_false, parse_null, parse_number, parse_object, parse_string, parse_true, scan_ctrl_char, scan_false, scan_null, scan_number, scan_string, scan_true, utoj

This file is part of the (main) package.

Source code.

Details
Procedures:

_dectohex(val)


 Given an integer value, return a hexidecimal string


_octtohex(s)


 Given an octal string, returns a hexadecimal string. Uses Unicon octal
 specifications


_utoj(u, jerror)


 Given a Unicon structure, produce a JSON equivalent if possible.

 TODO: Check for fails that need error messages


json_parser(token_gen, jerror)


 Takes a co-expression to generate JSON tokens.
 Returns a Unicon equivalent JSON structure.


json_scanner(s, jerror)


 A string-scanning generator - takes a JSON-formatted string 
 and returns single JSON tokens until scanning is complete


jsonify_string(s, jerror)


 Procedure for converting Unicon escapes and escape sequences to valid 
 JSON escape sequences.


jtou(s, strict, mode, error)


 Takes a string s that will be interpreted as JSON data.
 If the conversion fails, jtou() attempts to use s as a
 filename. If it fails, then the function fails.

 This procedure is a generator. It will return the 
 corresponding unicon objects, one-by-one, until the
 conversion is complete.

 <[param s - JSON-encoded string or JSON filename]>
 <[param strict - Flag for specifing strict JSON syntax (non-null)]>
 <[param mode - Specifies explicit string, "s", or file, "f", handling]>
 <[param error - file for error messages (defaults to <tt>&errout</tt>)]>


jtouf(s, strict, error)

Parameters:
s
- JSON filename
strict
- Flag for specifing strict JSON syntax (non-null)
error
- file for error messages (defaults to &errout)
Returns:
unicon entity encoded in JSON string

Simple interface to convert a JSON file into a unicon entity.


jtous(s, strict, error)

Parameters:
s
- JSON-encoded string
strict
- Flag for specifing strict JSON syntax (non-null)
error
- file for error messages (defaults to &errout)
Returns:
unicon entity encoded in JSON string

Simple interface to convert a JSON string into a unicon entity. Note: Unlike jtou(), this assumes the JSON string contains a single unicon entity.


main(argv)


 For scanner speed testing


parse_array(token, token_gen, parse_funcs, jerror)


 Helper parsing function recognizes the production rules for a JSON array.
 Returns a Unicon list if the syntax is proper (success).


parse_false(token, token_gen, parse_funcs, jerror)


 Returns a string to represent a boolean false


parse_null(token, token_gen, parse_funcs, jerror)


 Returns the null value


parse_number(token, token_gen, parse_funcs, jerror)


 Returns the numeric() of the token


parse_object(token, token_gen, parse_funcs, jerror)


 Helper parsing function that recognizes the production rules for a
 JSON object. Returns a Unicon object (table, class, record, set, or cset) 
 if successfully parsed.


parse_string(token, token_gen, parse_funcs, jerror)


 Removes the delimiting double-quotes from the token. Converts to cset if
 there are delimiting single-quotes within the double-quotes.


parse_true(token, token_gen, parse_funcs, jerror)


 Returns a string to represent a boolean true


scan_ctrl_char(jerror)


 String scanning helper function that finds a valid JSON escape sequence
 and returns a valid Unicon escape or escape sequence if possible.


scan_false(jerror)


 String scanning helper function to retrieve JSON value 'false'


scan_null(jerror)


 String scanning helper function to retrieve JSON value 'null'


scan_number(c, jerror)


 String scanning helper function that returns a JSON number as a string


scan_string(jerror)


 String scanning helper function that identifies a JSON string and 
 returns a Unicon string


scan_true(jerror)


 String scanning helper function to retrieve JSON value 'true'


utoj(x, strict, error)


 It is insane to propose a single function as the primary API for the
 entire library, so here it is.

 Given a Unicon structure, produce a JSON equivalent if possible.

 An optional second parameter, error, as a file handle will specify 
 where to print an error message in the event of a error



This page produced by UniDoc on 2021/04/15 @ 23:59:54.