问题描述
我想遍历一个像这样的JSON节点(即/node.json)
I want to traverse a JSON Node which is like this (i.e./node.json)
{
"One": {
"Name": "One",
"Country": "US"
},
"Two": {
"State": "kentucky"
},
"Three": {
"Element1": "value1",
"Element2": "value2",
"Element3": "value3",
"Element4": "value4",
so on ...
}
}
已更新我的用例:我尝试使用以下配置运行CORB作业
UpdatedMy Usecase : I tried to run a CORB job with below configurations
Transform.xqy(我将所有元素保留在一个数组中)
Transform.xqy (Where I am keeping all the elements in an array)
var name = fn.tokenize(URI, ";");
const node = cts.doc(name);
var a= node.xpath("/One/*");
var b= node.xpath("/Two/*");
var c= node.xpath("/Three/*");
fn.stringJoin([a, b, c,name], " , ")
当开始运行CORB作业以在我的marklogic DB中为130万个文档创建CSV文件时,这是一个永无止境的故事.
When started running the CORB job to create CSV file for 1.3 M documents in my marklogic DB, it is a never ending story.
推荐答案
已更新为使用Corb中的批处理
updated to use batch from Corb
好.根据故障单中的更多信息:(1)您没有遍历uri(2)您正在对嵌套数组进行联接.似乎很奇怪.
OK. Based on more info in the ticket:(1) You are not iterating over the uris(2) You are doing a join on a nested array. Seems odd.
我的示例文档:
declareUpdate()
let obj = {
One: {
Name: "One",
Country: "US"
},
Two: {
State: "kentucky"
},
Three: {
Element1: "value1",
Element2: "value2",
Element3: "value3",
Element4: "value4"
}
}
xdmp.documentInsert('/test1.json', obj)
xdmp.documentInsert('/test2.json', obj)
根据示例,我认为可以在您的模块中使用的代码. uris是模仿来自Corb的分批uris:
Based on the example, code that I think would work in your module. The uris is to mimic the batched uris coming from Corb:
let uris= '/test1.json;/test2.json'
let rows = uris.split(';')
rows.map(uri => {
let obj = fn.head(fn.doc(uri)).toObject()
return [
...Object.keys(obj.One).map(k => obj.One[k]),
...Object.keys(obj.Two).map(k => obj.Two[k]),
...Object.keys(obj.Three).map(k => obj.Three[k])
].join(',')
}).join('\n')
结果:
One,US,kentucky,value1,value2,value3,value4
One,US,kentucky,value1,value2,value3,value4
这篇关于在marklogic中使用Javascript遍历Json节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!