简体   繁体   English

我需要使用JSONATA以下格式的这个json数据

[英]I need this json data in the below format using JSONATA

Below json is my input. json以下是我的输入。

{
    "payload": {
        "KA01B3432": "KA01B3432",
        "KA02A3123": "KA02A3123"
    }
}

Using JSONATA i need to format the above JSON to below format. 使用JSONATA我需要将上面的JSON格式化为以下格式。

[
    {
        "KA01B3432": "KA01B3432"
    },
    {
        "KA02A3123": "KA02A3123"
    }
]

I tried payload.[$keys()] but this will yield only keys in array format not whole object in array format. 我尝试了payload.[$keys()]但这只会产生数组格式的键而不是数组格式的整个对象。

{
    "payload": {
        "KA01B3432": "KA01B3432",
        "KA02A3123": "KA02A3123"
    }
}

to

[
    {
        "KA01B3432": "KA01B3432"
    },
    {
        "KA02A3123": "KA02A3123"
    }
]

What about the following code : 以下代码如何:

   var json = { "payload": { "KA01B3432": "KA01B34321", "KA02A3123": "KA02A31231" } };
    var array = [];
    keys = Object.keys(json.payload);
    values = Object.values(json.payload);
    for (var i = 0; i < keys.length; i++) {
        var item = {};
        item[keys[i]] =  values[i];

        array.push(item);
    }
    console.log(array);

$spread(payload) does what you need. $spread(payload)可以满足您的需求。

See http://try.jsonata.org/S1COdDqO4 http://try.jsonata.org/S1COdDqO4

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

相关问题 如何使用 JSONATA 对 JSON 数据进行分组 - How to perform group-by over JSON data using JSONATA 如何获取下面的json并使用Realm存储它? 我有困难,只需要数据部分 - How to fetch below json and store it using Realm? I am having difficulty just need data part 需要使用 Hive 数据框出 JSON 格式 - Need to frame a JSON format using Hive data 如何使用 JSONata 按密钥对 JSON object 进行分组 - How to group the JSON object by a key using JSONata 如何使用jsonata在json中展平arrays的数组 - How to flatten array of arrays in json using jsonata 如何使用 json.dumps() 格式化我的 Python 字典以匹配以下 JSON 格式 - How can I format my Python dictionary to match the below JSON format using json.dumps() 我如何在nodejs中实现以下目标? 需要以JSON格式显示函数的输出 - How can I achieve below in nodejs? Need to display output of function in JSON format 我正在接收以下格式的日志,我需要将其转换为 python 字典以提取数据,得到 JSONDecodeError - I am recieving logs which is in below format, I need to convert this to python dictionary to extract the data, getting JSONDecodeError 如何将json数据转换为以下提到的格式 - How to convert the json data to the below mentioned format 需要以 JSON 格式发送数据 - need for sending data in JSON format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM