简体   繁体   English

如何在XQUERY Marklogic中获取json doc的每个字段?

[英]How to get each field of json doc in XQUERY Marklogic?

How to get each field of json doc in XQUERY Marklogic?如何在XQUERY Marklogic中获取json doc的每个字段?

let $doc :=
{
"field1" :'t',
"field2" : 'th',
"filed4": 'the'

}

return
$doc//??,
{
"New Filed" : "Added"
}

So how can we get the output like below ?那么我们怎样才能得到如下的输出呢?

{ "field1" :'t', "field2" : 'th', "filed4": 'the' ,"New Filed" : "Added"}

One approach: use the xdmp:from-json() to convert the immutable JSON node to a mutable map and then set the field:一种方法:使用xdmp:from-json()将不可变 JSON 节点转换为可变映射,然后设置字段:

return xdmp:from-json($doc) => map:with("NewField", "Added")

For more detail, see: https://docs.marklogic.com/xdmp:from-json有关更多详细信息,请参阅: https : //docs.marklogic.com/xdmp : from-json

Hoping that helps,希望有所帮助,

A JSON object is really just a specialized map. JSON 对象实际上只是一个专门的映射。 So you can use map operators, like the + union operator :所以你可以使用地图操作符,比如+ union 操作符

let $doc := object-node
{
"field1" :'t',
"field2" : 'th',
"filed4": 'the'
}

return 
  $doc + map:entry("NewField", "added")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM