Javascript JSON: Difference between revisions

From Yate Documentation
Jump to navigation Jump to search
No edit summary
Marian (talk | contribs)
Line 41: Line 41:
Return:<br/>
Return:<br/>
TRUE if operation succeeded, FALSE if an error occured.
TRUE if operation succeeded, FALSE if an error occured.
* '''replaceParams(obj, params [,sqlEscape [,extraEsc]])
Replace ${paramname} instances in 'buf' from 'params' field values.<br>
Replacements are done in string property values.<br>
Parameters:<br>
'''buf''': Array: replace in its elements. Object: replace in its properties. Any other type is ignored<br>
'''params''': Object whose fields are used to replace. Ignored (no replace is made) if not an object<br>
'''sqlEscape''': Optional. True to apply SQL escaping to parameter values<br>
'''extraEsc''': Character to escape other than the SQL default ones<br>

Revision as of 14:00, 10 April 2018

JSON parsing global object.

Methods

  • parse(str)

Parse JSON string.

Parameters:
str String containing JSON data
Return:
Primitive type or object representing the data, undefined if parsing failed.


  • stringify(obj,unused,spaces)

Stringify a Javascript primitive or object.

Parameters:
obj Object of primitive type
unused Unused optional parameter, for compatibility with the standard
spaces Optional number of spaces to use for indentation
Return:
String JSON data, undefined is an error occured.


  • loadFile(name)

Parse JSON file (non-standard method).

Parameters:
name Name of the file containing JSON data
Return:
Primitive type or object representing the data, undefined if parsing failed.


  • saveFile(name,obj,spaces)

Save JSON data in a file (non-standard method).

Parameters:
name Name of the JSON file to write
unused Unused optional parameter, for compatibility with the standard
spaces Optional number of spaces to use for indentation
Return:
TRUE if operation succeeded, FALSE if an error occured.


  • replaceParams(obj, params [,sqlEscape [,extraEsc]])

Replace ${paramname} instances in 'buf' from 'params' field values.
Replacements are done in string property values.
Parameters:
buf: Array: replace in its elements. Object: replace in its properties. Any other type is ignored
params: Object whose fields are used to replace. Ignored (no replace is made) if not an object
sqlEscape: Optional. True to apply SQL escaping to parameter values
extraEsc: Character to escape other than the SQL default ones