Skip to content

Instantly share code, notes, and snippets.

@bonbizin
Last active October 6, 2015 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonbizin/69c6063b58a590972065 to your computer and use it in GitHub Desktop.
Save bonbizin/69c6063b58a590972065 to your computer and use it in GitHub Desktop.
XQuery to convert JSON file to XML

XQuery to convert JSON file to XML

Assumes that a BaseX database product_feed was created previously using the xquey:

db:create("product_feed")
  1. XQuery Code

let $name := "/abc/shopclue-ProductFeed.json"
let $file := file:read-text($name)
let $json := json:parse($file)
let $database :="product_feed"
return db:add($database, $json, $name)

If the JSON key containing any space or special chars ar escaped; for example "Merchant Rating" is converted to Merchant_0020Rating

let $name := "/home/ashish/playground/abc/shopclue-ProductFeed.json"
let $file := file:read-text($name)
let $json := json:parse($file)
let $database :="delme"
return db:add($database, $json, $name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment