保留一些 json 键值对,同时使用 jolt 转换它们
Retain some json key value pairs while transforming them using jolt
我刚开始学习 jolt。我想将 json 转换为所需的格式。我快完成了,但坚持这一点
我的输入 json 看起来像
{ "first_name": {
"label": "First name",
"type": "text",
"value": "John"
},
"last_name": {
"label": "Last name",
"type": "text",
"value": "Doe"
},
"email": {
"label": "Email",
"type": "text",
"value": "johndoe@gmail.com"
}
"id": 123,
"marital_status": "Single",
"author_id": null,
"company": null,
"address": {
"city": {
"label": "city",
"dom_type": "dropdown",
"value": "test"
},
"state": {
"label": "state",
"dom_type": "dropdown",
"value": "state"
},
"country": {
"label": "country",
"dom_type": "dropdown",
"value": "country"
}
}
}
到这样的输出格式
{
"first_name" : "John", "last_name" : "Doe", "email" : "johndoe@gmail.com",
"id": 123, "marital_status": "Single", "author_id": null, "company": null,
"address" : { "city" : "test", "state" : "test", "country" : "test" }
}
我试过这个换档规范
[
{
"operation": "shift",
"spec": {
"address": {
"*": {
"@value": "address.&1"
}
},
"*": {
"@value": "&1"
}
}
}
]
得到了
{
"first_name" : "John", "last_name" : "Doe", "email" : "johndoe@gmail.com", "address" : { "city" : "test", "state" : "test", "country" : "test" }
}
因为匹配器“*”丢弃了简单的键值对。我知道我错过了什么。有帮助吗?
因为匹配器“*”丢弃了简单的键值对。 -> 它不是丢弃它们,而是匹配它们,但没有找到 "value" 的子 属性。
您的输入数据基本上采用 3 种不同的格式
- 地址下面的东西
- 价值单一的事物,例如"id"
- 具有嵌套数据的事物
“*”正好匹配左侧的 / 键。
在这种情况下,您需要明确列出单数键或具有嵌套数据的键。
规格
[
{
"operation": "shift",
"spec": {
"address": {
"*": {
"@value": "address.&1"
}
},
"id|marital_status|author_id|company": "&",
"*": {
"@value": "&1"
}
}
}
]
我刚开始学习 jolt。我想将 json 转换为所需的格式。我快完成了,但坚持这一点
我的输入 json 看起来像
{ "first_name": {
"label": "First name",
"type": "text",
"value": "John"
},
"last_name": {
"label": "Last name",
"type": "text",
"value": "Doe"
},
"email": {
"label": "Email",
"type": "text",
"value": "johndoe@gmail.com"
}
"id": 123,
"marital_status": "Single",
"author_id": null,
"company": null,
"address": {
"city": {
"label": "city",
"dom_type": "dropdown",
"value": "test"
},
"state": {
"label": "state",
"dom_type": "dropdown",
"value": "state"
},
"country": {
"label": "country",
"dom_type": "dropdown",
"value": "country"
}
}
}
到这样的输出格式
{
"first_name" : "John", "last_name" : "Doe", "email" : "johndoe@gmail.com",
"id": 123, "marital_status": "Single", "author_id": null, "company": null,
"address" : { "city" : "test", "state" : "test", "country" : "test" }
}
我试过这个换档规范
[
{
"operation": "shift",
"spec": {
"address": {
"*": {
"@value": "address.&1"
}
},
"*": {
"@value": "&1"
}
}
}
]
得到了
{
"first_name" : "John", "last_name" : "Doe", "email" : "johndoe@gmail.com", "address" : { "city" : "test", "state" : "test", "country" : "test" }
}
因为匹配器“*”丢弃了简单的键值对。我知道我错过了什么。有帮助吗?
因为匹配器“*”丢弃了简单的键值对。 -> 它不是丢弃它们,而是匹配它们,但没有找到 "value" 的子 属性。
您的输入数据基本上采用 3 种不同的格式
- 地址下面的东西
- 价值单一的事物,例如"id"
- 具有嵌套数据的事物
“*”正好匹配左侧的 / 键。
在这种情况下,您需要明确列出单数键或具有嵌套数据的键。
规格
[
{
"operation": "shift",
"spec": {
"address": {
"*": {
"@value": "address.&1"
}
},
"id|marital_status|author_id|company": "&",
"*": {
"@value": "&1"
}
}
}
]