简体   繁体   English

如何将Json列表转换为键值对象

[英]How to trasform a Json list to a key-value object

I have a Json with this structure: 我有一个具有以下结构的Json:

{"code":"0000",
 "usercode":"sample",
 "specifications":{ 
    "c":"d","e":"f"
}}

I need to build a jolt to convert the json to this form: 我需要建立一个颠簸来将json转换为这种形式:

{"code":"0000",
 "usercode":"sample",
 "specifications":[
      {"key":"c",
       "value":"d"},
      {"key":"e",
       "value":"f"}
]}

I tried this, but is my first jolt. 我试过了,但这是我的第一个震动。

[
  {
    "operation": "shift",
    "spec": {
      "code": "code",
      "usercode": "usercode",
      "specifications": {
        "*": {
          "key": "@c",
          "value": "@d"
        }
      }
    }
  }
]

First check this example: https://jolt-demo.appspot.com/#mapToList to understand whats going on :) 首先检查以下示例: https : //jolt-demo.appspot.com/#mapToList以了解发生了什么:)

This spec will do the trick: 该规范将达到目的:

[
  {
    "operation": "shift",
    "spec": {
      "code": "&",
      "usercode": "&",
      "specifications": {
        "*": {
          "$": "&2[#2].key",
          "@": "&2[#2].value"
        }
      }
    }
  }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将键值对的JSON数组转换为JSON对象? - How to convert JSON array of key-value pairs to JSON object? JSON对象作为键值对中的键 - JSON object as key in key-value pair 如何在postgresql中将两行转换为键值json对象? - How to convert two rows into key-value json object in postgresql? 如何在AngularJS中按键值过滤json列表? - How do you filter a json list by key-value in AngularJS? 如何使用键值格式打破JSON? - How to break JSON with key-value format? 在javascript中将Json对象转换为键值对的Json数组 - Convert Json object to Json array of key-value pair in javascript 如何使用jq在JSON对象中的指定键之后插入键值对? - How to insert a key-value pair after a specified key in a JSON object using jq? 如何将Python MySQLdb SELECT结果格式化为json.dumps,键值对出现在json对象中 - How to format Python MySQLdb SELECT result into json.dumps, key-value pairs to be present in json object 如何从具有单个“键值”的 JSON 对象中提取单个值? - How to extract a single value from a JSON object with a single "key-value"? 如何使用Casablanca在现有的web :: json :: value对象中附加新的键值对? - How to append new key-value pairs in an existing web::json::value object using Casablanca?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM