[MarkLogic Dev General] General Digest, Vol 129, Issue 20

Himalaya Naidupyla Himalaya_Naidupyla at infosys.com
Thu Mar 12 22:48:28 PDT 2015


Please don't send presently mails to me
  I will contact to u later



Thanks,
Himalaya



-----Original Message-----
From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of general-request at developer.marklogic.com
Sent: Friday, March 13, 2015 11:17 AM
To: general at developer.marklogic.com
Subject: General Digest, Vol 129, Issue 20

Send General mailing list submissions to
	general at developer.marklogic.com

To subscribe or unsubscribe via the World Wide Web, visit
	http://developer.marklogic.com/mailman/listinfo/general
or, via email, send a message with subject or body 'help' to
	general-request at developer.marklogic.com

You can reach the person managing the list at
	general-owner at developer.marklogic.com

When replying, please edit your Subject line so it is more specific than "Re: Contents of General digest..."


Today's Topics:

   1. Re: Constructing JSON objects (Sudhakar Reddy)
   2. Re: Constructing JSON objects (Will Thompson)
   3. Re: Constructing JSON objects (Michael Blakeley)
   4. Re: Constructing JSON objects (David Lee)
   5. Nested cts:search() functions over JSON	documents (Nick Ardlie)
   6. Re: Nested cts:search() functions over JSON documents
      (Geert Josten)


----------------------------------------------------------------------

Message: 1
Date: Thu, 12 Mar 2015 21:38:38 +0000
From: Sudhakar Reddy <Sudhakar.Reddy at marklogic.com>
Subject: Re: [MarkLogic Dev General] Constructing JSON objects
To: MarkLogic Developer Discussion <general at developer.marklogic.com>
Message-ID: <D1275498.3EF88%sreddy at marklogic.com>
Content-Type: text/plain; charset="us-ascii"

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



------------------------------

Message: 2
Date: Fri, 13 Mar 2015 00:35:59 +0000
From: Will Thompson <wthompson at jonesmcclure.com>
Subject: Re: [MarkLogic Dev General] Constructing JSON objects
To: MarkLogic Developer Discussion <general at developer.marklogic.com>
Message-ID: <2B1B330B-C558-46DE-92F1-0C3E09D67718 at jonesmcclure.com>
Content-Type: text/plain; charset="us-ascii"

Thanks all. The ML8 constructors look very nice.

Mike - That's what I was looking for, thanks. I ended up writing something similar using json:array before I saw the reply, but I like your implementation better. Also, I appropriated the json: prefix because it looked nicer...for example, is there any reason why this would be bad (other than ML might decide implement it at some later date)? 

declare function json:new(...)

-W

> On Mar 12, 2015, at 4:38 PM, Sudhakar Reddy <Sudhakar.Reddy at marklogic.com> wrote:
> 
> 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
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general



------------------------------

Message: 3
Date: Thu, 12 Mar 2015 18:51:40 -0700
From: Michael Blakeley <mike at blakeley.com>
Subject: Re: [MarkLogic Dev General] Constructing JSON objects
To: MarkLogic Developer Discussion <general at developer.marklogic.com>
Message-ID: <308C412D-6638-422A-9BEB-D9E7CFB76A52 at blakeley.com>
Content-Type: text/plain; charset=us-ascii

I tend to avoid declaring functions or variables in any namespace that I know other code is using. But you're doing it with your eyes open, and that's probably ok. Someday a server update may conflict. But if that happens, I'm sure you'll catch it in testing, and fix it before it breaks production.

Right?

-- Mike  

> On 12 Mar 2015, at 17:35 , Will Thompson <wthompson at jonesmcclure.com> wrote:
> 
> Thanks all. The ML8 constructors look very nice.
> 
> Mike - That's what I was looking for, thanks. I ended up writing something similar using json:array before I saw the reply, but I like your implementation better. Also, I appropriated the json: prefix because it looked nicer...for example, is there any reason why this would be bad (other than ML might decide implement it at some later date)? 
> 
> declare function json:new(...)
> 
> -W
> 
>> On Mar 12, 2015, at 4:38 PM, Sudhakar Reddy <Sudhakar.Reddy at marklogic.com> wrote:
>> 
>> 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
>> 
>> _______________________________________________
>> 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
> 



------------------------------

Message: 4
Date: Fri, 13 Mar 2015 02:36:03 +0000
From: David Lee <David.Lee at marklogic.com>
Subject: Re: [MarkLogic Dev General] Constructing JSON objects
To: MarkLogic Developer Discussion <general at developer.marklogic.com>
Message-ID: <3AE00F49-0E3B-410F-A00B-390863987AFA at marklogic.com>
Content-Type: text/plain; charset="us-ascii"

Making an XQuery function to call the explicit constructor with variable key names or number  of keys is not possible directly There isn't the equivalent of map:entry , field names are constant expressions and the number of fields is constant, unlike element {}{}

You would have to resort to string conversions, in memory node operations or evals ...  Or stick with json:object() /json:array() Or write it in Javascript 

In all cases what would the signature be?   A fundamental mismatch between XQuery an JSON is sequences vs arrays there are no vararg functions and any construct to nest or bound sequences involves a lot of syntax and temporary objects.

If you come up with something let us know!  





Sent from my iPad (excuse the terseness) David A Lee dlee at marklogic.com


> On Mar 12, 2015, at 9:51 PM, Michael Blakeley <mike at blakeley.com> wrote:
> 
> I tend to avoid declaring functions or variables in any namespace that I know other code is using. But you're doing it with your eyes open, and that's probably ok. Someday a server update may conflict. But if that happens, I'm sure you'll catch it in testing, and fix it before it breaks production.
> 
> Right?
> 
> -- Mike  
> 
>> On 12 Mar 2015, at 17:35 , Will Thompson <wthompson at jonesmcclure.com> wrote:
>> 
>> Thanks all. The ML8 constructors look very nice.
>> 
>> Mike - That's what I was looking for, thanks. I ended up writing something similar using json:array before I saw the reply, but I like your implementation better. Also, I appropriated the json: prefix because it looked nicer...for example, is there any reason why this would be bad (other than ML might decide implement it at some later date)? 
>> 
>> declare function json:new(...)
>> 
>> -W
>> 
>>> On Mar 12, 2015, at 4:38 PM, Sudhakar Reddy <Sudhakar.Reddy at marklogic.com> wrote:
>>> 
>>> 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
>>> 
>>> _______________________________________________
>>> 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
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general


------------------------------

Message: 5
Date: Fri, 13 Mar 2015 16:34:18 +1100
From: Nick Ardlie <nick.ardlie at gmail.com>
Subject: [MarkLogic Dev General] Nested cts:search() functions over
	JSON	documents
To: general at developer.marklogic.com
Message-ID:
	<CANf16qd=A=qWja+iq9q1_cfkYKB91DzJgsgDpjsvz0D8oeQ7Pw at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Is it possible to define nested (i.e. path constrained) queries in
cts:search() over JSON document types in MarkLogic 8?

With XML document types I can nest cts:element-query() functions to achieve
this.
But I don't seem to be able to use the cts:element-query() function for
JSON.
Unless I'm missing something? It requires an xs:QName() parameter and a
local-name only version of a QName doesn't seem to work for JSON documents.

To describe with an example, say I have the following documents (one XML,
the other JSON):

let $xml-doc :=
<doc>
<foo>
<bar>UP HERE</bar>
</foo>
<baz>
<foo>
<bar>DOWN HERE</bar>
</foo>
</baz>
</doc>

let $json-doc := xdmp:unquote(
'{
"foo": {
"bar": "UP HERE"
},
"baz": {
"foo": {
"bar": "DOWN HERE"
}
}
}')

let $insert-result := (xdmp:document-insert("ID-1", $json-doc),
xdmp:document-insert("ID-2", $xml-doc))


With the XML document I can search for foo/bar elements that contain the
word "here" like this:
return cts:search(doc(), cts:element-query(xs:QName("foo"),
cts:element-query(xs:QName("bar"), "here")))

After the above insert this will match the XML document but not the JSON
document.
I'd like to do the equivalent with the JSON document but the similar cts
functions for JSON don't appear to support cts:query nesting (e.g.
cts:json-property-value-query()).
Is there a way to do this with JSON documents?
I know I can constrain the first expression argument to cts:search with an
XPath.
But I'm interested to know if I can achieve this entirely within cts:query
constructs/functions.

Regards,
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150313/cb442f47/attachment-0001.html 

------------------------------

Message: 6
Date: Fri, 13 Mar 2015 05:47:12 +0000
From: Geert Josten <Geert.Josten at marklogic.com>
Subject: Re: [MarkLogic Dev General] Nested cts:search() functions
	over JSON documents
To: MarkLogic Developer Discussion <general at developer.marklogic.com>
Message-ID: <D1283851.85F5A%geert.josten at marklogic.com>
Content-Type: text/plain; charset="us-ascii"

Hi Nick,

I think you are looking cts:json-property-scope-query:

xquery version "1.0-ml";

let $json-doc := xdmp:unquote(
'{
"foo": {
"bar": "UP HERE"
},
"baz": {
"foo": {
"bar": "DOWN HERE"
}
}
}')

return xdmp:document-insert("/doc.json", $json-doc)
;
"element search",
cts:search(doc(), cts:element-query(xs:QName("foo"), cts:element-query(xs:QName("bar"), "here"))),
"json search",
cts:search(doc(), cts:json-property-scope-query("foo", cts:json-property-scope-query("bar", "here")))

Cheers,
Geert

From: Nick Ardlie <nick.ardlie at gmail.com<mailto:nick.ardlie at gmail.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Friday, March 13, 2015 at 6:34 AM
To: "general at developer.marklogic.com<mailto:general at developer.marklogic.com>" <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: [MarkLogic Dev General] Nested cts:search() functions over JSON documents

Is it possible to define nested (i.e. path constrained) queries in cts:search() over JSON document types in MarkLogic 8?

With XML document types I can nest cts:element-query() functions to achieve this.
But I don't seem to be able to use the cts:element-query() function for JSON.
Unless I'm missing something? It requires an xs:QName() parameter and a local-name only version of a QName doesn't seem to work for JSON documents.

To describe with an example, say I have the following documents (one XML, the other JSON):

let $xml-doc :=
<doc>
<foo>
<bar>UP HERE</bar>
</foo>
<baz>
<foo>
<bar>DOWN HERE</bar>
</foo>
</baz>
</doc>

let $json-doc := xdmp:unquote(
'{
"foo": {
"bar": "UP HERE"
},
"baz": {
"foo": {
"bar": "DOWN HERE"
}
}
}')

let $insert-result := (xdmp:document-insert("ID-1", $json-doc), xdmp:document-insert("ID-2", $xml-doc))


With the XML document I can search for foo/bar elements that contain the word "here" like this:
return cts:search(doc(), cts:element-query(xs:QName("foo"), cts:element-query(xs:QName("bar"), "here")))

After the above insert this will match the XML document but not the JSON document.
I'd like to do the equivalent with the JSON document but the similar cts functions for JSON don't appear to support cts:query nesting (e.g. cts:json-property-value-query()).
Is there a way to do this with JSON documents?
I know I can constrain the first expression argument to cts:search with an XPath.
But I'm interested to know if I can achieve this entirely within cts:query constructs/functions.

Regards,
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150313/cb4dbfac/attachment.html 

------------------------------

_______________________________________________
General mailing list
General at developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


End of General Digest, Vol 129, Issue 20
****************************************

**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are not 
to copy, disclose, or distribute this e-mail or its contents to any other person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has taken 
every reasonable precaution to minimize this risk, but is not liable for any damage 
you may sustain as a result of any virus in this e-mail. You should carry out your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***


More information about the General mailing list