[MarkLogic Dev General] Using Json Extensions

Jonathan Cook jonathan.cook2 at bbc.co.uk
Thu Mar 15 01:45:29 PDT 2012


Thanks for the links. I just saw the extension and thought it looked
interesting and was curious if it actually worked.

We are doing our translation pragmatically with some third party java
libraries because as you say it is a tricky business!

Jon


On 14/03/2012 23:37, "Danny Sokolsky" <Danny.Sokolsky at marklogic.com> wrote:

> And here are a few more examples in the documentation:
>  
> http://docs.marklogic.com/5.0doc/docapp.xqy#display.xqy?fname=http://pubs/5.0d
> oc/xml/dev_guide/json.xml
>  
> -Danny
>  
> 
> From: general-bounces at developer.marklogic.com
> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Justin Makeig
> Sent: Wednesday, March 14, 2012 3:36 PM
> To: MarkLogic Developer Discussion
> Subject: Re: [MarkLogic Dev General] Using Json Extensions
>  
> Jon,
> 
> Are you trying to convert XML to JSON? In your example, you¹re calling
> fn:data() on the XML input. fn:data returns the atomic value of whatever you
> give it. In your case, you get back the text of all of your nodes as a single
> string. Calling xdmp:to-json on a string returns that string. In order to
> create nested JSON structures with xdmp:to-json, you¹ll have provide it
> map:map instances
> <http://developer.marklogic.com:8040/5.0doc/docapp.xqy#search.xqy?query=map%3A
> map 
> <http://developer.marklogic.com:8040/5.0doc/docapp.xqy#search.xqy?query=map:ma
> p> >. Translating XML structures to JSON in the general case is actually
> pretty tricky business. Today, there¹s an open-source, community-supported
> library called mljson <https://github.com/marklogic/mljson> that provides some
> conversion capabilities. You might take a look at that. If the structure of
> the XML you¹re converting into JSON is pretty predictable you might consider
> building a custom translation either into map:map or a raw JSON string using
> XSLT or XQuery. We¹re also looking to improve the built-in JSON support in
> MarkLogic as well. If you could provide some more details on what you¹re
> trying to accomplish others on this list or I may be able to help more.
> 
>  
> 
> Justin
> 
> 
> Justin Makeig
> Senior Product Manager
> MarkLogic Corporation
> justin.makeig at marklogic.com
> Phone: +1 650 655 2387
> www.marklogic.com <http://www.marklogic.com/>
> 
>  
> 
> On Mar 14, 2012, at 2:56 PM, Jonathan Cook - FM&T wrote:
> 
> 
> But what comes out isn't Json?
> 
> eg)
> 
> "highwebdomesticIDX10447671Europe2010-06-29T09:56:21+00:002012-03-12T12:05:58+
> 00:002012-03-14T16:33:29+00:00PUBLISHEDen-GBNews v6cpsSTYOECD sees signs of
> Europe pick-upThe eurozone shows \"tentative\" signs of recovery, says the
> Organisation for Economic Co-operation and
> Development.2012-03-12T11:57:15+00:002012-03-12T12:04:31+00:00en-GBEuropean
> flagsSTYEurogroup eye on Greece and SpainFinance ministers from eurozone
> nations are set to discuss Greece's bailout and Spain's deficit at a meeting
> on Monday.2012-03-12T09:58:04+00:002012-03-12T13:37:24+00:00en-GBProtests in
> MadridSTYQ&A: Greek debt
> swap2012-03-07T10:14:44+00:002012-03-09T12:39:11+00:00en-GB2012-02-16T09:20:32
> +00:00Spain sees its economy contract2012-03-09T11:23:34+00:00Flanders: Where
> are we now?2012-03-09T08:53:51+00:00Hewitt: Greece deal is temporary
> reliefSTYVolkswagen forecasts record salesVolkswagen says sales could hit a
> record in 2012 as strong growth continues in emerging
> markets.2012-03-12T08:06:40+00:002012-03-12T14:39:54+00:00en-GBVW
> logo2012-02-24T10:50:53+00:00Volkswagen annual profits doubleSTYBMW sees its
> profits 
> accelerate2012-03-08T12:17:53+00:002012-03-08T13:03:21+00:00en-GBSTYCarmakers
> show their sharing
> side2012-02-28T13:33:34+00:002012-03-05T21:41:45+00:00en-GBSTYSwatch and
> Tiffany in legal fightSwatch and Tiffany are suing each other following the
> collapse of their joint venture last
> year.2012-03-12T07:28:36+00:002012-03-12T08:01:35+00:00en-GBSwatch Gents
> Watch2012-01-10T11:54:18+00:00Swatch eyes further sales growthSTYSarkozy
> threat over open bordersPresident Nicolas Sarkozy tells a campaign rally that
> France will withdraw from Europe's open borders agreement unless illegal
> immigration is 
> tackled.2012-03-11T16:00:57+00:002012-03-11T16:59:10+00:00en-GBPresident
> Nicolas SarkozySTYQ&A: Schengen
> Agreement2011-04-26T10:36:50+00:002012-03-12T13:43:40+00:00en-GBSTYFrance 'has
> too many 
> foreigners'2012-03-06T21:34:01+00:002012-03-07T06:47:09+00:00en-GB2012-03-07T2
> 2:34:11+00:00Sarkozy: Too many foreigners in FranceSTYGKN 'planning Volvo
> engine deal'GKN is reported to be in advanced talks to buy the aircraft engine
> unit of Volvo for
> \u00A3800m.2012-03-11T08:46:56+00:002012-03-11T08:59:40+00:00en-GBGripen
> combat jetSTYABN Amro takes large Greek lossDutch bank ABN Amro says its
> underlying net profit for 2011 was undermined by bad debt charges, including
> 880m euros for 
> Greece.2012-03-09T09:23:30+00:002012-03-09T10:34:28+00:00en-GBABN is expected
> to be split up when the takeover is completedABN Amro officeSTYRecord
> deliveries at Airbus ownerEuropean aerospace giant EADS reports higher annual
> profits as it delivers a record amount of its Airbus aircraft to
> customers.2012-03-08T07:04:20+00:002012-03-08T11:44:09+00:00en-GBAirbus
> A320STYChina 'bars Airbus deals' on
> levy2012-03-08T10:45:09+00:002012-03-08T18:25:40+00:00en-GB2012-02-15T12:00:28
> +00:00Airbus inquiry into wing cracksSTYUK interest rates remain at 0.5%UK
> interest rates are kept at 0.5% by the Bank of England, marking three years
> since they were first cut to the record
> low.2012-03-08T11:45:59+00:002012-03-08T15:25:11+00:00en-GBBank of
> England2012-03-06T19:01:17+00:00Flanders: QE for whom?STYThree years of
> record-low rates2012-03-01T15:45:02+00:002012-03-04T18:18:13+00:00en-GBSTYQE
> knocks \u00A390bn off pension
> funds2012-03-07T12:24:34+00:002012-03-08T07:06:43+00:00en-GBSTYFamily split on
> low interest 
> rates2012-03-02T12:01:59+00:002012-03-03T00:07:21+00:00en-GBSTYAllied Irish to
> shed 2,500 jobsAllied Irish Banks, the parent company of First Trust in
> Northern Ireland, confirms that it is cutting its workforce across the UK and
> Ireland by 2,500.2012-03-08T10:39:35+00:002012-03-08T11:07:48+00:00en-GBAllied
> Irish Banks is to cut its workforce by 2,500AIBSTYBMW sees its profits
> accelerateGerman carmaker BMW says it made a record profit margin in its core
> car business last year, helped by strong demand from
> China.2012-03-08T12:17:53+00:002012-03-08T13:03:21+00:00en-GBSales to China
> are still growing fastBMW logoSTYRetailer Carrefour in profit fallNet profits
> at French supermarket group Carrefour, the world's second-biggest retailer by
> revenue, fell by 14% in
> 2011.2012-03-08T09:55:37+00:002012-03-08T10:30:41+00:00en-GBA branch of
> CarrefourSTYForeign visitors boost EurostarEurostar says passenger numbers
> rose 2% to 9.7 million last year, with business helped by a rise in visitors
> from outside the 
> EU.2012-03-08T07:34:58+00:002012-03-08T09:33:21+00:00en-GBEurostar train at St
> PancrasSTYPower fault brings Eurostar
> chaos2012-03-05T22:37:09+00:002012-03-06T10:25:26+00:00en-GBSTYEurotunnel
> swings back to 
> profit2012-03-01T12:50:23+00:002012-03-01T12:55:05+00:00en-GBSTYLufthansa
> pushed into loss by BMIGerman airline Lufthansa reports an annual loss of 13m
> euros as a result of losses and disposal costs at its BMI
> subsidiary.2012-03-07T17:11:30+00:002012-03-07T17:17:29+00:00en-GBLufthansa
> tail finsSTYAdidas sees record profit in 2011Sportswear firm Adidas unveils
> its best-ever annual profits, as hopes rise this year's Olympics will help it
> break more 
> records.2012-03-07T08:04:09+00:002012-03-07T09:41:38+00:00en-GBAdidas hopes
> the UEFA championships will help deliver record earningsAdidas hopes the UEFA
> championships will help deliver record earnings2011-08-04T06:19:47+00:00Adidas
> increases profit forecast2011-03-02T07:22:10+00:00Adidas sees record sales for
> 2010STYStocks down on Greek swap fearsStock markets decline sharply on
> concerns ahead of a key deadline to secure Greece's future in the
> euro.2012-03-06T16:30:10+00:002012-03-06T21:22:37+00:00en-GBAnxious trader at
> the Frankfurt Stock ExchangeSTYQ&A: Greek debt
> crisis2011-06-16T15:21:08+00:002012-03-02T09:32:06+00:00en-GB2012-01-30T11:39:
> 21+00:00Why Greece won't go away2011-06-21T10:59:31+00:00Timeline of Eurozone
> crisisSTYSwiss eye tax rise for foreignersSwitzerland moves closer towards
> enforcing higher rates of tax on the country's 5,000 wealthiest foreign
> residents.2012-03-06T15:52:50+00:002012-03-06T16:00:03+00:00en-GBSwiss
> parliament in BernSTYRange Rover shows convertible 4x4Jaguar Land Rover
> unveils a convertible Range Rover Evoque design study at the Geneva motor
> show, while Mini shows off a new vehicle, the
> Clubvan.2012-03-06T13:22:44+00:002012-03-06T13:42:37+00:00en-GBThe Evoque
> Cabrio is the latest concept car from Jaguar Land RoverEvoque
> Cabrio2011-10-31T12:46:54+00:00Infiniti tees up as BMW
> rival2011-09-15T15:02:50+00:00Mercedes to help Nissan make luxury carsSTYEU
> calls for more women managersThe EU considers legislating to get more women
> into top management jobs in Europe, arguing that firms are too slow to
> act.2012-03-05T12:52:55+00:002012-03-05T13:33:30+00:00en-GBEU Justice
> Commissioner Viviane Reding2012-03-05T09:39:01+00:00Peston: Time to force
> women into boardrooms?2011-02-23T17:50:22+00:00More women in boardroom
> demandedSTYEurozone's retail sales increaseRetail sales across the eurozone
> rose unexpectedly in January, figures show, but a separate survey indicates
> economic activity remains
> weak.2012-03-05T10:23:49+00:002012-03-05T11:17:13+00:00en-GBGermany's retail
> sales fell in JanuaryGermany's retail sales fell in
> January2012-01-06T10:40:06+00:00Euro unemployment stays at
> record2011-11-07T11:08:13+00:00Eurozone retail sales disappointSTYGlencore
> profits from commoditiesCommodities trading giant Glencore reports a sharp
> rise in revenues on the back of higher prices for raw
> materials.2012-03-05T08:12:13+00:002012-03-05T08:36:44+00:00en-GBGlencore
> headquarters2012-02-07T08:55:34+00:00Glencore and Xstrata: a merger of
> egosSTYMoody's downgrades Greece againMoody's cuts Greece's credit rating
> again to \"C\", the lowest level on its scale, warning of default despite a
> recent debt write-off
> deal.2012-03-02T23:42:49+00:002012-03-03T00:03:29+00:00en-GBGreek Parliament
> building2012-02-22T12:18:52+00:00Fitch cuts Greece's rating againSTYSpanish
> 'to miss deficit target'Spain Prime Minister Mariano Rajoy says his country
> will miss its budget deficit target this year, as EU leaders agree a new
> treaty on budget 
> discipline.2012-03-02T13:14:01+00:002012-03-02T14:00:13+00:00en-GBSpanish
> Prime Minister Mariano Rajoy2012-02-16T09:20:32+00:00Spain sees its economy
> contract2012-02-15T06:22:55+00:00Europe struck by growth slowdownSTYEU leaders
> sign new fiscal treatyAll but two of the EU's 27 leaders sign a new treaty to
> enforce budget discipline within the bloc and rein in
> debts.2012-03-02T08:34:27+00:002012-03-02T15:50:11+00:00en-GBDanish PM Helle
> Thorning-Schmidt (left) signs fiscal treaty, with Germany's Chancellor Angela
> Merkel2012-03-02T15:37:50+00:00Hewitt: Hope comes to eurozoneSTYQ&A: Fiscal
> compact2011-12-06T20:05:16+00:002012-03-02T10:37:00+00:00en-GBSTYSpain 'to
> miss deficit 
> target'2012-03-02T13:14:01+00:002012-03-02T14:00:13+00:00en-GBSTYPM claims EU
> summit win on 
> growth2012-03-01T20:54:46+00:002012-03-02T17:12:49+00:00en-GB2012-03-02T12:02:
> 04+00:00Cameron 'made voice heard'STYGermany retail sales slide backGerman
> retail sales fell unexpectedly in January by 1.6%, the biggest drop since May
> last year, official figures
> show.2012-03-02T09:36:26+00:002012-03-02T10:02:05+00:00en-GBGerman
> shoppers2012-02-13T14:49:36+00:00Germany: Reasons to be cheerfulSTYBarclays
> taps ECB for 8.2bn eurosBarclays confirms that it borrowed 8.2bn euros
> (\u00A36.7bn) from the European Central Bank in low-interest three-year
> loans.2012-03-02T09:48:04+00:002012-03-02T15:34:13+00:00en-GBBarclays Bank
> signs2012-03-02T14:45:46+00:00Peston: British banks borrow \u00A331bnSTYECB
> provides 530bn euros of
> loans2012-02-29T09:35:20+00:002012-02-29T13:11:13+00:00en-GBSTYItaly's debts
> increased in 2011Italy's government debt rose during 2011 while its economy
> struggled to grow, official figures
> show.2012-03-02T10:52:50+00:002012-03-02T11:42:04+00:00en-GBView of
> Venice2012-01-17T22:56:44+00:00Risks of Italy's austerity
> measures2012-02-13T14:49:36+00:00Germany looks on the bright
> side2012-02-14T10:31:55+00:00Greek recession deepens in 2011STYC&W Worldwide
> shares in new leapShares in Cable & Wireless Worldwide (CWW) jump sharply for
> the second time in three weeks on hopes of a takeover
> battle.2012-03-01T12:48:56+00:002012-03-01T13:05:05+00:00en-GBModemSTYEurotunn
> el swings back to profitEurotunnel, the operator of the Channel Tunnel,
> returned to profit in 2011 with a record 19 million
> passengers.2012-03-01T12:50:23+00:002012-03-01T12:55:05+00:00en-GB2011-03-04T0
> 8:26:59+00:00Eurotunnel reports 57m euro loss"
> 
> 
> -----Original Message-----
> From: general-bounces at developer.marklogic.com on behalf of Will Thompson
> Sent: Wed 14.03.2012 21:12
> To: MarkLogic Developer Discussion
> Subject: Re: [MarkLogic Dev General] Using Json Extensions
> 
> Jon,
> 
> That's is how xdmp:to-json works for XML nodes.
> 
> http://docs.marklogic.com/5.0doc/docapp.xqy#search.xqy?query=to-json
> 
> -Will
> 
> From: general-bounces at developer.marklogic.com
> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Jonathan Cook -
> FM&T
> Sent: Wednesday, March 14, 2012 2:00 PM
> To: MarkLogic Developer Discussion
> Subject: [MarkLogic Dev General] Using Json Extensions
> 
> 
> Hi,
> 
> Has anyone successfully got the json extensions working, I have been playing
> around with the below but you don't get json coming out, just a long string of
> the element values from the xml?
> 
> Thanks
> Jon
> 
> let $newsml := 
> doc('http://www.bbc.co.uk/asset/b5c53243-e52f-e059-e040-850a02846523/highweb/d
> omestic')
> return xdmp:to-json(fn:data($newsml))
> 
> _______________________________________________
> 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


http://www.bbc.co.uk/
This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
					
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20120315/a5ef2d93/attachment-0001.html 


More information about the General mailing list