json:config( $strategy as xs:string ) as map:map
This function creates a configuration object for a specified strategy.
Parameters | |
---|---|
strategy | The name of
the strategy. One of basic (simple default JSON
conversion, starting from JSON), full (starting from
XML), or custom . |
basic
, full
,
custom
.
The basic
strategy is used if you supply no
parameters and has no user customizable properties.
The following properties are user customizable to configure the
behavior of the transformation.
full
strategy propertiesProperty |
Description |
Default value |
---|---|---|
|
The member named used to contain attributes |
|
|
The member named used to contain the children array |
|
|
How to treat whitespace in XML text
values when converting to JSON. If
|
empty string |
custom
strategy propertiesProperty |
Description |
Direction |
Type |
Default value |
---|---|---|---|---|
|
A list of XML element names which will be
treated as an Array in JSON. These can be
|
XML to JSON |
|
() |
|
A list of XML element names which will be
ignored when transformed to JSON. These can be
|
XML to JSON |
|
() |
|
A list of XML attribute names which will be
ignored when transformed to JSON. These can be
|
XML to JSON |
|
() |
|
The JSON member name to use for text when an element contains both attributes and text. |
BOTH |
xs:string |
|
|
A list of JSON names which are converted to XML attribute. |
JSON to XML |
|
() |
|
A boolean value indicating if camel case transformation is applied to all element and attribute names when translating to and from JSON. |
BOTH |
|
|
|
The default namespace for elements |
JSON to XML |
|
() |
|
The default prefix for elements |
JSON to XML |
|
() |
|
The default namespace for attributes |
JSON to XML |
|
() |
|
The default prefix for attributes |
JSON to XML |
xs:string |
() |
|
If specified then when converting to JSON attributes are prefixed with this string. When converting to XML all names starting with this prefix are converted to attributes with the prefix removed. |
BOTH |
xs:string |
() |
|
A list of XML element names which will
be treated as an |
BOTH |
(xs:QName | xs:string)* |
() |
|
The member named used to contain
attributes when using the
|
xs:string |
|
|
|
The member named used to
contain the children array when using the
|
|
|
|
|
How to treat whitespace in
XML text values when converting to JSON.
If |
|
|
"" |
xquery version "1.0-ml"; import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy"; let $c := json:config("full"), return json:transform-to-json( fn:doc("sample.xml") , $c )
xquery version "1.0-ml"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy"; let $custom := let $config := json:config("custom") return (map:put($config, "array-element-names", ("text","point","value","operator-state", "annotation","uri","qtext")), map:put($config, "element-namespace", "http://marklogic.com/appservices/search"), map:put($config, "element-namespace-prefix", "search"), map:put($config, "attribute-names",("warning","name")), map:put($config, "full-element-names", ("query","and-query","near-query","or-query")), map:put($config, "json-children","queries"), $config) let $struct := search:parse("hello world", (), "search:query") return ( json:transform-to-json($struct, $custom), $struct ) (: returns the json and corresponding XML for the structured query :) => {"query":{"queries": [{"and-query":{"queries": [{"term-query":{"text":["hello"]}}, {"term-query":{"text":["world"]}}]} }] }} <search:query xmlns:search="http://marklogic.com/appservices/search"> <search:and-query> <search:term-query> <search:text>hello</search:text> </search:term-query> <search:term-query> <search:text>world</search:text> </search:term-query> </search:and-query> </search:query>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.