File json.icn |
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.
This file is part of the (main) package.
Source code.Details |
Procedures: |
Given an integer value, return a hexidecimal string
Given an octal string, returns a hexadecimal string. Uses Unicon octal specifications
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.
A string-scanning generator - takes a JSON-formatted string and returns single JSON tokens until scanning is complete
Procedure for converting Unicon escapes and escape sequences to valid JSON escape sequences.
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>)]>
s | - JSON filename |
strict | - Flag for specifing strict JSON syntax (non-null) |
error | - file for error messages (defaults to &errout) |
unicon entity encoded in JSON string |
Simple interface to convert a JSON file into a unicon entity.
s | - JSON-encoded string |
strict | - Flag for specifing strict JSON syntax (non-null) |
error | - file for error messages (defaults to &errout) |
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.
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
String scanning helper function that finds a valid JSON escape sequence and returns a valid Unicon escape or escape sequence if possible.
String scanning helper function to retrieve JSON value 'false'
String scanning helper function to retrieve JSON value 'null'
String scanning helper function that returns a JSON number as a string
String scanning helper function that identifies a JSON string and returns a Unicon string
String scanning helper function to retrieve JSON value 'true'
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