我刚刚开始学习震动。我想将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" }
}
因为匹配器“ *”会丢弃简单的键值对。我知道我想念一些东西。有帮助吗?
答案 0 :(得分:1)
因为匹配器“ *”会丢弃简单的键值对。 ->它不是在丢弃它们,而是在匹配它们,但找不到“值”的子属性。
您的输入数据基本上采用3种不同的格式
“ *”仅与左侧的/键匹配。
在这种情况下,您将需要显式列出单个的键或具有嵌套数据的键。
规格
Unhandled rejection RequestError: Error: read ECONNRESET