jsSerialize

Converts a JSON container  to plain text.

Syntax:

jsSerialize ( container-handle, formatted [, encoding] )

Parameters:

(s) container-handle: extender container handle to serialize.

(s) formatted: (@True|@False) true means add indentation and line terminators to return string.

(s) encoding: [optional] (@JsonUTF8(1)|@JsonUTF16(2)) character encoding of the return string. Defaults to @JsonUTF8.

Returns:

(s) json-text: syntactically valid text presentation of JSON data.

 

This function accepts a extender JSON container handle and converts the container back to its full text representation. Depending on formatting and character encoding the returned text can be saved to a file, sent to printer or sent to a Web server.

 

Container-Handle

The unique identifier returned from a call to the jsParse, jsObjNew, jsValueGet functions, or by accessing WIL map element returned by the jsConMap function.

  

Formatted

Set to @True (1) to causes the function to return human-readable text suitable for printing or writing to a file. Specify @False (0) for unformatted text the can be saved to a file or sent over the Internet.

  

Encoding

An optional parameter used to indicate the Unicode character encoding of the returned text.

  

Constant

Meaning

@JsonUTF8 (1)

Encode the return text in UTF-8 Unicode. UTF-8 is the JSON standard encoding. This is the default when the parameter is not used.

@JsonUTF16 (2)

Encode the return text in UTF-16 Unicode. UTF-16 is the character encoding native to Windows and WinBatch string functions.

 
Example:
  AddExtender('ilcjs44i.dll', 0, 'ilcjs64i.dll')
  
  ; JSON object text.
  strJson = $"{"pi":: 3.141,"happy":: true,"name":: "WIL JSON Extender",
    "nothing":: null,"answer":: {"everything":: 42},"list":: [1, 0, 2],
    "object":: {"currency":: "USD","value":: 42.99,"nested object":: {
    "value":: "bird egg"}},"value":: "Top level value"}$"
  
  Json = jsParse(strJson)
  ; Get formatted jason.
  FormJson =  jsSerialize(Json ,@true, @JsonUTF16)
  jsConClose()
  ; Print using a temporary file.
  Temp = FileCreateTemp("TMP")
  Temp = StrReplace(Temp,'.tmp', '.txt')
  FilePut(Temp,FormJson)
  ; Send to the default printer
  Print(Temp,'', @hidden,0)
  TimeDelay(3)
  FileDelete(Temp)
  
See Also:

jsParse, jsValueAdd