WARNING: This server provides a static reference view of the NetKernel documentation. Links to dynamic content do not work. For the best experience we recommend you install NetKernel and view the documentation in the live system .

Endpoint
Name:json.JSONFromXML
Description:
Id:json.JSONFromXML
Category:accessor
Identifier Syntax

json.JSONFromXML is an accessor using Active URI syntax with the following base identifiers:

Base
active:JSONFromXML

and the following arguments: (for more details on argument passing details see here)

ArgumentRulesTypingDescription
operand
Mandatory
Representation (java.lang.String)input XML document
operator
Optional
Representation (java.lang.Object)(no description available)
Request Verbs

The following verb is supported:

Verb
SOURCE
Response

The following response representations can be returned for SOURCE requests:

SOURCE Representations
JSONObject

This accessor throws no documented exceptions.

Import Requirements

To use json.JSONFromXML accessor you must import the module urn:org:netkernel:json:core:

<import>
  <uri>urn:org:netkernel:json:core</uri>
</import>

Example

This XML resource...

<root>
  <a>1</a>
  <b>2</b>
</root>

will be converted to the following JSON

{"root":
	{
		"a": "1",
		"b": "2"
	}
}

Operator

The optional operator argument supplies configuration to the conversion

<config>
  <removeRootElement>true</removeRootElement>
</config>

  • removeRootElement - removes the root element from the generated JSON. So using the example we would have:

{
	"a": "1",
	"b": "2"
}

Warning

Please be aware the JSON and XML are not isomorphic and so developers should take care to ensure that their data translates correctly. This note in the Json library is important...

"Convert a well-formed (but not necessarily valid) XML string into a JSONObject. Some information may be lost in this transformation because JSON is a data format and XML is a document format. XML uses elements, attributes, and content text, while JSON uses unordered collections of name/value pairs and arrays of values. JSON does not does not like to distinguish between elements and attributes. Sequences of similar elements are represented as JSONArrays. Content text may be placed in a "content" member. Comments, prologs, DTDs, and
<[ [ ]]>
are ignored."