Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用jolt转换json键值对时,保留一些json键值对_Json_Jolt - Fatal编程技术网

在使用jolt转换json键值对时,保留一些json键值对

在使用jolt转换json键值对时,保留一些json键值对,json,jolt,Json,Jolt,我刚开始学习震动。我想将json转换为所需的格式。我几乎完成了,但仍坚持这一点 我的输入json看起来像 { "first_name": { "label": "First name", "type": "text", "value": "John" }, "last_name": { "label": "Last name", "type": "text", "value": "Doe" }, "email": { "la

我刚开始学习震动。我想将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"
          }
        }
      }
    ]