This API documentation is for Ballerina 1.2.0. View API documentation for the latest release.

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.

 table<Person> tableValue = table{
     { key id, age, salary, name, married },
     [ { 1, 30,  300.5, "Mary", true },
         { 2, 20,  300.5, "John", 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