Great, thanks very much - I'll look into that. From: [email protected] [mailto:[email protected]] On Behalf Of Joe Bryan Sent: Monday, December 14, 2015 11:08 AM To: MarkLogic Developer Discussion <[email protected]> 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: <[email protected]<mailto:[email protected]>> on behalf of Kari Cowan <[email protected]<mailto:[email protected]>> Reply-To: MarkLogic Developer Discussion <[email protected]<mailto:[email protected]>> Date: Monday, December 14, 2015 at 1:42 PM To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> 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.
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
