Skip to content

JSON steps

Martin Kraetke edited this page Feb 5, 2019 · 6 revisions

Just some random thoughts on which steps might be needed for JSON documents.

Joining JSON documents together

<p:join-JSON>
  <p:input port="source" sequence="true" content-types="application/json" />
  <p:output port="result" content-types="application/json" />
  <p:option name="flatten-arrays" as="xs:boolean" select="false()" />
</p:p:join-JSON>

The same as wrap-sequence for XML and text documents. The result port contains a JSON document with an array containing all the documents on the source port as entries.

Selecting from a JSON document

<p:select-from-JSON>
  <p:input port="source" content-types="application/json" />
  <p:option name="selector" as="xs:anyAtomicType+" required="true" />
  <p:option name="complement" as="xs:boolean" default="false()"/>
  <p:output port="result" sequence="true" content-types="application/json" />
</p:select-from-JSON>

Returns a portion of the JSON document on the source port as a new JSON document on the result port. If source is a map, $selector is taken as the key, if it is an array, $selector must be an integer with the index. In any other case it is an error.

Selector can be a list Error if an array then its an error if the selector is not only a non-negative integer

Replacing entries in JSON documents

<p:replace-in-JSON>
  <p:input port="source" content-types="application/json" />
  <p:option name="selector" as="xs:anyAtomicType" required="true" />
  <p:option name="value" as="item()*" required="true" />
  <p:output port="result" content-types="application/json" /> 
</p:replace-in-JSON

Replaces a piece in the JSON document with a new value. If source is a map, $selector is taken as the key. If there is no entry with this key, nothing will happen. Otherwise a new JSON document with a map is return, where the key-entry is associated with the new value. If source is an array, $selector must be an integer. If the array has such an entry, a new JSON document with an array is return, where [$selector] is $value.

Delete in a JSON document

<p:delete-in-JSON>
  <p:input port="source" content-types="application/json" />
  <p:option name="selector" as="xs:anyAtomicType" required="true()" />
  <p:output port="result" />
</p:delete-in-JSON>

Validation with JSON schema

Should be moved to validation steps.

<p:validate-with-json-schema>
  <p:input port="source" primary="true" content-types="application/json"/>
  <p:input port="schema" content-types="application/json"/>
  <p:output port="result" content-types="application/xml"/>
  <p:option name="assert-valid" select="true()" as="xs:boolean"/>
</p:validate-with-json-schema>

Java implementations: