Class Index | File Index

Classes


Namespace jamJSON


Version 4.5.

Defined in: jamJSON.jsxinc.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Global object (used to simulate a namespace in JavaScript) containing customized JSON methods for translating a JavaScript data structure to and from a JSON text string; can be used in scripts written with the JSON Action Manager engine.
Method Summary
Method Attributes Method Name and Description
<static>  
jamJSON.parse(text, validate, allowComments)
Convert a JSON text string into a JavaScript data structure.
<static>  
jamJSON.stringify(value, space, prefix)
Convert a JavaScript data structure into a JSON text string.
Namespace Detail
jamJSON
Global object (used to simulate a namespace in JavaScript) containing customized JSON methods for translating a JavaScript data structure to and from a JSON text string; can be used in scripts written with the JSON Action Manager engine.
  • Adapted from: json_parse_state.js and json2.js by Douglas CrockFord.
  • Spotted and fixed a few problems in the Photoshop implementation of the JavaScript interpreter:
    • In regular expressions, hexadecimal escape sequences (both \x and \u) must be in capital letters (A-F).
    • The precedence of nested ternary operators ( ? : ) is handled differently, extra parentheses must be used.
    • The test (state instanceof SyntaxError) returns true even if state is a ReferenceError; in fact, it seems that all error types: Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, are just synonyms for each other; therefore, one must check beforehand if a function is missing in the action table before calling it, so that no ReferenceError gets ever thrown...

Author: Michel MARIANI.
Method Detail
<static> {Object|Array|String|Number|Boolean|Null} jamJSON.parse(text, validate, allowComments)
Convert a JSON text string into a JavaScript data structure.
var jsonText = '{ "Last Name": "Einstein", "First Name": "Albert" }';
try
{
    var jsObj = jamJSON.parse (jsonText, true);
    alert (jsObj["First Name"] + " " + jsObj["Last Name"]);    // -> Albert Einstein
}
catch (e)
{
    alert ("E≠mc2!");
}
Parameters:
{String} text
JSON text string
{Boolean} validate Optional
validate JSON syntax while parsing
{Boolean} allowComments Optional
validate comments too
Returns:
{Object|Array|String|Number|Boolean|Null} JavaScript data structure (usually an object or array)
See:
jamJSON.stringify

<static> {String} jamJSON.stringify(value, space, prefix)
Convert a JavaScript data structure into a JSON text string.
var dummy = null;
var jsArr =
[
    3.14E0,
    'Hello ' + 'JSON!',
    { on: (0 === 0) },
    [ 1 + 1, dummy ]
];
alert (jamJSON.stringify (jsArr));  // -> [ 3.14, "Hello JSON!", { "on": true }, [ 2, null ] ]
Parameters:
{Object|Array|String|Number|Boolean|Null} value
JavaScript data structure (usually an object or array)
{String|Number} space Optional
Indent space string (e.g. "\t") or number of spaces
{String|Number} prefix Optional
Prefix space string (e.g. "\t") or number of spaces
Returns:
{String} JSON text string
See:
jamJSON.parse

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 12 2016 23:32:44 GMT+0200 (CEST)