Functions - jsonutils

fromTable

Converts a table to its JSON representation.

fromXML

Converts an XML object to its JSON representation.

fromTable

(table tableValue)

returns json

Converts a table to its JSON representation.

 type Employee record {
      int id;
      string name;
      float salary;
      boolean permanent;
  };
 table<Employee> tableValue = table[ { id: 1, name: "Mary",  salary: 300.5, permanent: true },
         { id: 2, name: "John",  salary: 300.5, permanent: true }
     ];
 json jsonValue = jsonutils:fromTable(tableValue);

Parameters

  • tableValue table
  • The source table to be converted to JSON

  • Return Type

    (json)
  • The JSON representation of the source table

fromXML

(xml x, XmlOptions options)

returns json | error

Converts an XML object to its JSON representation.

 xml xmlValue = xml `<!-- outer comment -->` + xml `<name>supun</name>`;
 json|error jsonValue = fromXML(mxlValue);

Parameters

  • x xml
  • The XML source to be converted to JSON

  • options XmlOptions (default {})
  • The XmlOptions record consisting of the configurations for the conversion

  • Return Type

    (json | error)
  • The JSON representation of the given XML on success, else returns an error