How to set the serialization parameters for exporting data with BaseX?

落花浮王杯 提交于 2021-01-29 09:25:28

问题


How can I export what originated as a JSONArray object into a valid JSON file? It seems to be a matter of setting some export options.

exporting the data file as XML:

thufir@dur:~/flwor/foo$ 
thufir@dur:~/flwor/foo$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
> 
> open foo_json
Database 'foo_json' was opened in 383.76 ms.
> 
> set parser json
PARSER: json
> 
> export /home/thufir/flwor/foo
Database 'foo_json' was exported in 16.11 ms.
> 
> exit
Enjoy life.
thufir@dur:~/flwor/foo$ 
thufir@dur:~/flwor/foo$ cat .json 
<json type="array">
  <_ type="object">
    <_0030>z10</_0030>
    <_0031>y9</_0031>
    <_0032>x7</_0032>
    <_0033>atrib6</_0033>
    <name>alice</name>
  </_>
  <_ type="object">
    <_0030>home5</_0030>
    <_0031>cell4</_0031>
    <name>sue</name>
  </_>
  <_ type="object">
    <_0030>phone3</_0030>
    <_0031>phone2</_0031>
    <_0032>phone1</_0032>
    <name>joe</name>
  </_>
  <_ type="object">
    <name>people</name>
  </_>
</json>thufir@dur:~/flwor/foo$ 
thufir@dur:~/flwor/foo$ 

Where it's actually XML, which is okay, but JSON would be preferred.

The database can be exported as stand-alone JSON through the GUI as:

resulting in:

thufir@dur:~/flwor/foo$ 
thufir@dur:~/flwor/foo$ cat .json 
[
  {
    "0":"z10",
    "1":"y9",
    "2":"x7",
    "3":"atrib6",
    "name":"alice"
  },
  {
    "0":"home5",
    "1":"cell4",
    "name":"sue"
  },
  {
    "0":"phone3",
    "1":"phone2",
    "2":"phone1",
    "name":"joe"
  },
  {
    "name":"people"
  }
]thufir@dur:~/flwor/foo$ 

So this is the desired output, but how is that output accomplished from the console?

Note that it's set as JSON and escape with the GUI. How are those parameters set from the console?

来源:https://stackoverflow.com/questions/60267586/how-to-set-the-serialization-parameters-for-exporting-data-with-basex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!