json - 保留一些 json 键值对,同时使用 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" }
}
因为匹配器“*”丢弃了简单的键值对。我知道我错过了一些东西。有什么帮助吗?
解决方案
因为匹配器“*”丢弃了简单的键值对。-> 它不是丢弃它们,而是匹配它们,但没有找到“值”的子属性。
您的输入数据基本上是 3 种不同的格式
- 地址下面的东西
- 像“id”这样价值单一的东西
- 有嵌套数据的东西
“*”只匹配左侧的 / 键。
在这种情况下,您将需要显式列出单数键或具有嵌套数据的键。
规格
[
{
"operation": "shift",
"spec": {
"address": {
"*": {
"@value": "address.&1"
}
},
"id|marital_status|author_id|company": "&",
"*": {
"@value": "&1"
}
}
}
]
推荐阅读
- cuda - 为什么小输入时 cpu 比 gpu 快?
- c++ - 如何标记要翻译的字符串?
- python - 使用 Python 分析日志
- python - 如何更改 tkinter OptionMenu 着色?
- python - 为什么 i+=1 行会阻止元组到字符串的转换?
- telerik - 如何使用 Telerik Radgrid UserControl 将文本框设置为只读
- c# - java.lang.illegalstateexception: '当前页面未完成!'
- computer-science - 应该连续运行的进程的术语 VS 运行直到完成
- c# - 实体框架 - 在调用 SaveChanges() 以添加/删除实体之前从上下文中获取更新的数据库集
- c# - 将 C# 对象与规则合并