Hi Jonathan,

> 1. Is there any way to import both JSON and XML files at the same time when
> creating a database?

Currently, only one input parser is supported at the same time. You’ll
either have to…

• import your data in various steps (a CREATE for all XML files,
followed by an ADD for JSON files, and, optionally and eventually,

• use XQuery (db:create, db:add, etc. [1], and possibly the File
Module) to define and convert all input files in one go.

> 2. I would like to import the JSON as an XQuery/XPath map, without mapping
> it to XML.  Any way to do that?

There store data in the database in a representation different to XML
(apart from our binary storage feature… But this one does not provide
any other features, such as indexing). However, in many cases, it’s
efficient enough to convert database entries to maps via fn:serialize
(or json:serialize) and fn:parse-json:

1. Example:

  document {
    <json type="object">
      <ααρων type="object">
        <gk type="number">2</gk>
        <strongs type="array">
          <_ type="number">2</_>
  => serialize(map { 'method': 'json' })
  => parse-json()

2. Example:

  declare function local:json-xml-to-map(
    $json as document-node(element(json))
  ) as map(*) {
  local:json-xml-to-map(db:open('db', 'my.json'))

Quite obviously, if you don’t want to store data in the database, you
can always use fn:json-doc ;)

Hope this helps,

[1] http://docs.basex.org/wiki/Database_Module

Reply via email to