简体   繁体   English

如何删除空的 object 标签

[英]How to remove empty object tags

Given the following JSON:给定以下 JSON:

{
      "identifers": {
        "_id": "f073895e207c3157",
        "attrsDigest": "-706912700",
        "entityTypes": [
          {
            "_id": "bacf9e903a6c5def",
            "attrsDigest": "1537152651"
          },
          {
            "_id": "08aac63dacd579c8",
            "attrsDigest": "-1461027456"
          }
        ],
        "statuses": [
          {
            "_id": "50912252d4781056",
            "attrsDigest": "154590869"
          }
        ]
      }
    }

I need to produce the following:我需要制作以下内容:

{
  "identifers": [
    {
      "_id": "f073895e207c3157",
      "attrsDigest": "-706912700"
    },
    {
        "_id": "bacf9e903a6c5def",
        "attrsDigest": "1537152651"
    },
    {
      "_id": "08aac63dacd579c8",
      "attrsDigest": "-1461027456"
    },
    {
      "_id": "50912252d4781056",
      "attrsDigest": "154590869"
    }
    ]
  }

I've got the following:我有以下内容:

[**].${ "identifers": _id, "digest": attrsDigest }

which produces this:产生这个:

{
  "identifers": [
    "f073895e207c3157",
    "bacf9e903a6c5def",
    "08aac63dacd579c8",
    "50912252d4781056"
  ],
  "digest": [
    "-706912700",
    "1537152651",
    "-1461027456",
    "154590869"
  ]
}

You can use the "reduce" operator to group your nested data by ID and then format it into an array of the desired shape:您可以使用“reduce”运算符按 ID 对嵌套数据进行分组,然后将其格式化为所需形状的数组:

**{ _id: attrsDigest }
  ~> $each(function($attrsDigest, $id) {
    { "_id": $id, "attrsDigest": $attrsDigest }
  })

Live playground: https://stedi.link/A1yo9Pz直播游乐场: https://stedi.link/A1yo9Pz

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM