The format stored when you upload data JSON data using REST is the same format 
you get when using
   xdmp:transform-from-json( "{ json data} " )

If you want to turn that back into JSON use
   xdmp:transform-to-json( < xml data from database > )

If you want to augment the data which is stored in the DB with your own JSON 
you can use instead

   xdmp:transform-to-json-object( < xml data from database > )

Which will produce a json:object

>From there you can add to this object and then finally use

   json:to-json(  json object )

to generate the actual JSON as a string


Is this what you were after ?
If not could you provide some more details on exactly what you are trying to 
accomplish ?





-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]
Phone: +1 812-482-5224
Cell:  +1 812-630-7622
www.marklogic.com<http://www.marklogic.com/>


From: [email protected] 
[mailto:[email protected]] On Behalf Of Steve Spigarelli
Sent: Monday, July 22, 2013 3:22 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] json:object

Thank you for your responses.

I'm trying to write a REST extension that can create a JSON object with some 
objects previously uploaded using the REST interface.

What I see to be the problem is that the REST interface translates the JSON 
into one format, and the json:map and json:array functions generate completely 
different internal XML structures. The files ingested with the REST interface 
require json:transform-to-json and json:map and json:array require xdmp:to-json 
to translate from XML to JSON.

Starting with JSON of {"hello": "world"} I see the following:

REST Interface (after upload):

<json type="object" xmlns="http://marklogic.com/xdmp/json/basic";>
  <hello type="string">world</hello>
</json>

and using json:object() I get:

json:object(
  <json:object xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:json="http://marklogic.com/xdmp/json";>
    <entry key="hello">
      <json:value xsi:type="xs:string">world</json:value>
    </entry>
  </json:object>
)

I would expect them to be the same. Is there a way to convert from one to the 
other?

Thanks
Steve


--
Steve

On Mon, Jul 22, 2013 at 12:47 PM, Danny Sokolsky 
<[email protected]<mailto:[email protected]>> wrote:
You can try looking through this section of the doc for a little more info too:

http://docs.marklogic.com/guide/app-dev/json

-Danny

From: 
[email protected]<mailto:[email protected]>
 
[mailto:[email protected]<mailto:[email protected]>]
 On Behalf Of David Lee
Sent: Monday, July 22, 2013 11:44 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] json:object

json:object is the in-memory representation of maps used for json.
The only difference between map:map and json:object is that the keys are 
ordered (which actually is not something JSON guarentees ... but we do).
Your "magic function" is xdmp:to-json().

You dont do a transformation on json:object  TO JSON ... its already in the 
form needed ...  You can turn it into a JSON string using  xdmp:to-json() but 
thats not a transformation.
Transformations occur between XML <-> JSON

Did that answer your question ?



-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]<mailto:[email protected]>
Phone: +1 812-482-5224<tel:%2B1%20812-482-5224>
Cell:  +1 812-630-7622<tel:%2B1%20812-630-7622>
www.marklogic.com<http://www.marklogic.com/>

From: 
[email protected]<mailto:[email protected]>
 
[mailto:[email protected]<mailto:[email protected]>]
 On Behalf Of Steve Spigarelli
Sent: Monday, July 22, 2013 2:39 PM
To: [email protected]<mailto:[email protected]>
Subject: [MarkLogic Dev General] json:object

I'm having a difficult time understanding what good the json:object() function 
is. From what I can tell after using it, it is a specialized map:map object. I 
have tried using json:transform-to-json on the object but the transform 
function doesn't like that.

So, what is the proper way to create a json:object and receive back the actual 
JSON string?

For example:

let $json-obj := json:object()
let $_ := map:put($json-obj, "key", "value")

return magic-function($json-obj) which would return {"key": "value"}

What I get instead by calling json:transform-to-json($json-obj) is an invalid 
coercion error. Even wrapping the object and passing the node doesn't work.

Any ideas? Has anyone actually used this function? From the comments in the 
documentation it doesn't have many comments. 
(http://docs.marklogic.com/json:transform-to-json)

--
Steve

_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to