使用Jolt重新父级JSON对象 [英] Re-parent a JSON object using Jolt
问题描述
我想使用Jolt将JSON对象向下移动一级。这是我的输入数据:
I'd like to move a JSON object down one level using Jolt. Here's my input data :
{
"rating": {
"primary": {
"value": 3,
"max": 5
},
"quality": {
"value": 3,
"max": 7
}
}
}
我正在使用以下规格文件:
I'm using the following spec file :
[
{
"operation": "shift",
"spec": {
"$": "NEWPARENT"
}
}
]
我目前正在制作此输出:
I'm currently producing this output :
{
"NEWPARENT" : "root"
}
但是,我的目标是制作:
However, my goal is to produce :
{
"NEWPARENT": {
"rating": {
"primary": {
"value": 3,
"max": 5
},
"quality": {
"value": 3,
"max": 7
}
}
}
}
任何人都可以帮我创建正确的spec文件吗?
Can anyone help me create the proper spec file?
推荐答案
Spec
[
{
"operation": "shift",
"spec": {
"@": "NEWPARENT"
}
}
]
仅供参考,您看到的根是Jolt处理顶级JSON输入可以是List或Map,以及您希望能够将List转换为映射(反之亦然)。
FYI, the "root" you are seeing is an artifact of the way that Jolt deals with the fact that the top level JSON input can be either a List or a Map, and that you want to be able to Transform a List into a Map (and vice versa).
因此,jolt包装输入,以便它始终转换具有单个键root的Map,作为输入的值。
So, jolt "wraps" the input so that it is "always" transforming a Map that has a single key "root", with a value that is the input.
这篇关于使用Jolt重新父级JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!