[MarkLogic Dev General] Constructing JSON objects

Sudhakar Reddy Sudhakar.Reddy at marklogic.com
Thu Mar 12 14:38:38 PDT 2015


You can also build using JSON node constructors available in ML 8
  let $json-node := object-node { "id": number-node {12345},
				"a" : array-node {1,2,3} ,
				"b" : fn:true(),
				"c" : number-node {1234},
				"d" : array-node{
						number-node {12345},
						text {"test"},
						boolean-node {fn:true()},
						array-node {'aaa','bbb','ccc'}},
						"e" : object-node { "x": "hello world",
						"y": fn:false(),
						"z" : array-node {1, 'a', fn:true()}
						},
				"g": null-node {}
				}  
				return $json-node

Thanks
Sudhakar



On 3/11/15, 6:52 PM, "Erik Hennum" <Erik.Hennum at marklogic.com> wrote:

>Hi, Will:
>
>You can use json:object() instead of map:map() for a mutable object where
>order is important.
>
>I think the API is the same as that of map:map otherwise.
>
>JSON nodes, like XML nodes, are immutable.
>
>Erik Hennum
>
>________________________________________
>From: general-bounces at developer.marklogic.com
>[general-bounces at developer.marklogic.com] on behalf of Will Thompson
>[wthompson at jonesmcclure.com]
>Sent: Tuesday, March 10, 2015 5:09 PM
>To: MarkLogic Developer Discussion
>Subject: [MarkLogic Dev General] Constructing JSON objects
>
>Is there a nice way to construct a JSON object similar to how maps can be
>constructed? Typically I would just do it this way:
>
>xdmp:to-json(
>  map:new((
>    map:entry('x', 1),
>    map:entry('y', 2)
>  )))
>
>Except that order is important in this specific scenario, and this ruins
>ordering.
>
>-Will
>_______________________________________________
>General mailing list
>General at developer.marklogic.com
>http://developer.marklogic.com/mailman/listinfo/general
>_______________________________________________
>General mailing list
>General at developer.marklogic.com
>http://developer.marklogic.com/mailman/listinfo/general



More information about the General mailing list