[MarkLogic Dev General] Custom JSON objects

Kari Cowan KCowan at alm.com
Tue Jan 19 06:24:27 PST 2016


It's ML 7

How would I get back the values of those nodes rather than the node paths?

From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Rajamani.Marimuthu at cognizant.com
Sent: Tuesday, January 19, 2016 5:00 AM
To: general at developer.marklogic.com
Subject: Re: [MarkLogic Dev General] Custom JSON objects

Hi,

Your code is working fine and getting expected result . Could you please tell me what version of ML  u r using.

By
Raja >>>

From: general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Kari Cowan
Sent: Tuesday, January 19, 2016 5:37 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Custom JSON objects

Just returning to this, I wanted to try constructing the map, but instead of getting back the values, I get back the document URI and path to the node.    Not what I expected.  What am I doing wrong?

let $outputSimpleJSON:=

  for $doc in $search-this-partner/event (: there are 3 records in this set :)

    let $theEvent:= $doc//EventTitle
    let $theStartDate:=$doc/EventStartDate

  let $map := map:new((
    map:entry("EventTitle", $theEvent),
    map:entry("EventStartDate", $theStartDate)
  ))

return xdmp:to-json($map)

>>

{"EventStartDate":"fn:doc(\"\/data-sources\/events\/Akira_7877013.xml\")\/event\/EventStartDate", "EventTitle":"fn:doc(\"\/data-sources\/events\/Akira_7877013.xml\")\/event\/EventTitle"}

{"EventStartDate":"fn:doc(\"\/data-sources\/events\/TheDayTheEarthStoodStillMarch08,2017.xml\")\/event\/EventStartDate", "EventTitle":"fn:doc(\"\/data-sources\/events\/TheDayTheEarthStoodStillMarch08,2017.xml\")\/event\/EventTitle"}

{"EventStartDate":"fn:doc(\"\/data-sources\/events\/Solaris_956351.xml\")\/event\/EventStartDate", "EventTitle":"fn:doc(\"\/data-sources\/events\/Solaris_956351.xml\")\/event\/EventTitle"}



From: general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Joe Bryan
Sent: Monday, December 14, 2015 11:08 AM
To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] Custom JSON objects

Hi Kari,

You can use the "custom" strategy with json:config(): http://docs.marklogic.com/json:config. There are lots of options that can be specified to control the transformation(for instance, "ignore-attribute-names").

Alternately, you can manipulate the resulting JSON object, or even code your own transformation. One of the simplest ways to implement your own transformation is to construct nested maps from the data you want, and then convert the map to json:

let $map := map:new((
  map:entry("key", "value"),
  map:entry("anotherKey", "a different value")
))
return xdmp:to-json($map)

Thanks.

-jb

From: <general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>> on behalf of Kari Cowan <KCowan at alm.com<mailto:KCowan at alm.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Monday, December 14, 2015 at 1:42 PM
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] Custom JSON objects

I had a question from someone on my team if it's possible to return a more simplified version JSON without child and attributes.

For example, compare Events JSON object:

http://data.smartlitigator.com/EventTools/GetEventsTable?display=New+York+Law+Journal|returnType=JSON

To this:

http://data.smartlitigator.com/QuestV2/Search/?query=law&publication=&section=&orgType=&elementType=&articleType=&practiceArea=&virtualPracticeArea=&subject=&industry=&source=lawcom&almStaff=&lawTopic=&fromDateTime=&toDateTime=&fromDate=1985-01-01&toDate=2015-11-07&start=1&end=10&sort=rank&direction=descending&returnType=falcon_json&callback=


Events, simply contructed snippet:

let $outputJSON:=("{&#34;events&#34;:[",
  let $config := json:config("full"),
      $cx := map:put( $config, "whitespace", "ignore" )
  return fn:string-join(
    for $doc at $counter in $search-this-partner/event
    order by $doc/EventStartDate/@date descending
    return xdmp:quote(json:transform-to-json($doc, $config)),","),
"]}")


Is it possible to specify which nodes and the format I want to convert, still using transform-to-json, or do I need to write a custom output myself?


________________________________
Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media Company, is a leading provider of news and information for the legal and commercial real estate markets. ALM's market-leading brands include The American Lawyer, Corporate Counsel, GlobeSt.com, Insight Conferences, Law.com, Law Journal Press, LegalTech, The National Law Journal and Real Estate Forum.
________________________________
Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media Company, is a leading provider of news and information for the legal and commercial real estate markets. ALM's market-leading brands include The American Lawyer, Corporate Counsel, GlobeSt.com, Insight Conferences, Law.com, Law Journal Press, LegalTech, The National Law Journal and Real Estate Forum.
This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20160119/15f36640/attachment-0001.html 


More information about the General mailing list