JOLT-根据对象值过滤数组

问题描述

我该怎么做? 这是数组。 你能帮我吗?

能给我答案吗????非常感谢

{
  "results": {
    "data": [
      {
        "name": "xx","typeRelationship": [
          {
            "relationship": "parent","type": {                
              "id": "yyyyy",}
          }
        ],"id": "xxxxxxxx"
      },{
        "name": "yy","typeRelationship": [
          {
            "relationshipType": "parent","type": {
              "id": "CCCC"
            }
          },{
            "relationshipType": "child","service": {
              "id": "dddd"
            }
          },"service": {
              "id": "xxxxxxxx"
            }
          }
        ],"id": "yyyyy"
      }
    ]
  }}

预期: 这是预期的:

{
  "data" : [ {
    "id" : "xxxx","href" : "xxxxxx","relation":"parent"
  } ]
}

由于某种原因,我需要输入内容,这样它才能让我更新!!!

解决方法

这有效。

[
  {
    "operation": "shift","spec": {
      "data": {
        "*": {
          "type": {
            "id": {
              "xxxx": {
                "@3": "data[]"
              }
            }
          }
        }
      }
    }
  }
]

编辑1

以下规范将所有id = xxxxx的值移动到数据数组。

[
  {
    "operation": "shift","spec": {
      "data": {
        "*": {
          "type": {
            "*": {
              "id": {
                "xxxx": {
                  "@(2)": "data[]","@(4,relation)": "data[&3].relation"
                }
              }
            }
          }
        }
      }
    }
  }
]
,

非常感谢您...

它可以工作,但是我发现输入错误。抱歉

{
  "data": [
    {
      "relation": "child","type": [
        {
          "id": "xxxx","href": "xxxxxx"
        }
      ]
    },{
      "relation": "parent","type": [
        {
          "id": "yyy","href": "yyy"
        }
      ]
    }
  ]
}

然后我需要它像这样:

{
  "data" : [ {
    "id" : "xxxx","href" : "xxxxxx","relation":"parent"
  } ]
}

可行吗??

,

这完全有效。 谢谢。 你能告诉我2是多少吗? 3? 4? 因为我的数组有点不同,所以我想修正这些数字,但是不起作用....

{
  "results": {
    "data": [
      {
        "name": "xx","typeRelationship": [
          {
            "relationship": "parent","type": {                
              "id": "yyyyy",}
          }
        ],"id": "xxxxxxxx"
      },{
        "name": "yy","typeRelationship": [
          {
            "relationshipType": "parent","type": {
              "id": "CCCC"
            }
          },{
            "relationshipType": "child","service": {
              "id": "DDDD"
            }
          },"service": {
              "id": "xxxxxxxx"
            }
          }
        ],"id": "yyyyy"
      }
    ]
  }

}

预期:

{
  "rows" : [  {
    "rowdata" : {
      "relationshipType" : "child","Name" : "yy","id" : "yyyyy"
    }
  } ]
}