It's ML 7 How would I get back the values rather than the node paths?
In other words, this: let $outputSimpleJSON:=("{"events":[", fn:string-join( 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:quote(xdmp:to-json($map)),","), "]}") Returns a valid JSON object for the 3 records returned, but it doesn't have the values of the data. Example: >> {"events":[ {"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"} ]} I need the values, like this - any way to do it? {"events":[ {"EventStartDate":"2018-03-08", "EventTitle":"Akira"}, {"EventStartDate":"2017-03-08", "EventTitle":"The Day The Earth Stood Still"}, {"EventStartDate":"2017-09-30", "EventTitle":"Solaris"} ]} From: general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com> [mailto:general-boun...@developer.marklogic.com] On Behalf Of rajamani.marimu...@cognizant.com<mailto:rajamani.marimu...@cognizant.com> Sent: Tuesday, January 19, 2016 5:00 AM To: general@developer.marklogic.com<mailto:general@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-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com> [mailto:general-boun...@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-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com> [mailto:general-boun...@developer.marklogic.com] On Behalf Of Joe Bryan Sent: Monday, December 14, 2015 11:08 AM To: MarkLogic Developer Discussion <general@developer.marklogic.com<mailto:general@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-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>> on behalf of Kari Cowan <kco...@alm.com<mailto:kco...@alm.com>> Reply-To: MarkLogic Developer Discussion <general@developer.marklogic.com<mailto:general@developer.marklogic.com>> Date: Monday, December 14, 2015 at 1:42 PM To: "general@developer.marklogic.com<mailto:general@developer.marklogic.com>" <general@developer.marklogic.com<mailto:general@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=§ion=&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:=("{"events":[", 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. ________________________________ 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.
_______________________________________________ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general