我需要帮助,我是新来的。有一个json文件:
{
"Date": "2021-01-01",
"Status": "New",
"Agreements": [
{
"ID_agreement": "12345",
"ID": "fffffff",
"balance": {
"rub": 5,
"usd": 6,
"eur": 7
},
"withdrawal": {
"rub": 8,
"usd": 45,
"eur": 6
}
},
{
"ID_agreement": "6789",
"ID": "dddddd",
"balance": {
"rub": 10,
"usd": 20,
"eur": 30
}
}
]
}
在输出时,您确实需要得到这样的信息:
{
"type": "DATA",
"date": "2021-01-01",
"id_agreement": "12345",
"id": "fffffff",
"source": "SITE",
"unloadDateTime": "current date if possible",
"balance": {
"rub": 5,
"usd": 6,
"eur": 7
},
"withdrawal": {
"rub": 8,
"usd": 45,
"eur": 6
}
},
{
"type": "DATA",
"date": "2021-01-01",
"id_agreement": "6789",
"id": "dddddd",
"source": "SITE",
"unloadDateTime": "current date if possible",
"balance": {
"rub": 10,
"usd": 20,
"eur": 30
}
必须将以下内容添加到每个块:
"type": "DATA",
"date": "2021-01-01",
"source": "SITE",
"unloadDateTime": "current date if possible"
和删除
"Status": "New"
原始文件很大,字段提取/余额在某个地方,而不是
我最初的颠簸规范:
[
{
"operation": "remove",
"spec": {
"Status": ""
}
},
{
"operation": "shift",
"spec": {
"Agreements": {
"*": "&"
},
"balance": {
"*": "&"
}
}
}
]
几个小时的拆解并没有导致任何事情,任务是一次性的,敬请各位同事帮忙!
发布于 2022-01-31 15:50:54
首先,位于底部的对象balance
是冗余的。删除后,应用#
表示法来提供您想要更新当前shift转换的固定值,如
[
{
"operation": "remove",
"spec": {
"Status": ""
}
},
{
"operation": "shift",
"spec": {
"Agreements": {
"*": {
"#DATA": "[&1].type",
"#2021-01-01": "[&1].date",
"#SITE": "[&1].source",
"#current date if possible": "[&1].unloadDateTime",
"*": {
"@": "[&2].&1"
}
}
}
}
}
]
https://stackoverflow.com/questions/70928284
复制相似问题