【问题标题】:JOLT - filtering array based on object valueJOLT - 基于对象值的过滤数组
【发布时间】:2020-12-11 06:26:50
【问题描述】:

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

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

{
  "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"
            }
          },
          {
            "relationshipType": "child",
            "service": {
              "id": "xxxxxxxx"
            }
          }
        ],
        "id": "yyyyy"
      }
    ]
  }}

预计: 这是预期的:

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

由于某种原因,我需要输入,所以它确实让我更新!!!

【问题讨论】:

    标签: jolt


    【解决方案1】:

    这完全有效。 谢谢。 你能告诉我什么是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"
                }
              },
              {
                "relationshipType": "child",
                "service": {
                  "id": "xxxxxxxx"
                }
              }
            ],
            "id": "yyyyy"
          }
        ]
      }
    

    }

    预期:

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

    【讨论】:

    • 这些数字是班次的计数,通配符 (@,$ 等) 确定班次的动作或方向。
    • 另外,通过编辑您的原始帖子或放置 cmets 来更新调查结果。不要将其添加到答案部分。所以,这篇文章对其他用户也有帮助。
    【解决方案2】:

    这行得通。

    [
      {
        "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"
                    }
                  }
                }
              }
            }
          }
        }
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 2020-07-04
      • 2016-11-17
      • 1970-01-01
      • 2019-09-08
      • 2019-04-29
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多