使用JOLT转换,我只需要从JSON有效负载中提取内容部分,需要JOLT规范

g9icjywg  于 2023-05-02  发布在  其他
关注(0)|答案(2)|浏览(99)
{
  "snippet-format": "empty-snippet",
  "total": 361,
  "start": 1,
  "page-length": 5,
  "selected": "include",
  "results": [
    {
      "index": 1,
      "uri": "/DEV/xyz-xyzRecord/OS1.json",
      "path": "fn:doc(\"/SIT1/xyz-xyzRecord/AB1.json\")",
      "score": 0,
      "confidence": 0,
      "fitness": 0,
      "href": "/v1/documents?uri=%2FDEV%2FIxyz-xyzRecord%2FOS1.json&database=data-hub-DEV",
      "mimetype": "application/json",
      "format": "json",
      "matches": null,
      "extracted": {
        "kind": "array",
        "content": [
          {
            "xyz": "AB1"
          }
        ]
      }
    }
  ]
}

预期输出为

[
  {
    "xyz": "AB1"
  }
]
ruoxqz4g

ruoxqz4g1#

您可以使用以下shift转换规范

[
  {
    "operation": "shift",
    "spec": {
      "@results[0].extracted.content": ""
    }
  }
]

另一个选择可能是

[
  {
    "operation": "shift",
    "spec": {
      "results": {
        "*": {
          "extracted": {
            "content": {
              "*": "[]"
            }
          }
        }
      }
    }
  }
]
nxowjjhe

nxowjjhe2#

@Barbaros但是如果多个物体

{
  "snippet-format": "empty-snippet",
  "total": 361,
  "start": 1,
  "page-length": 5,
  "selected": "include",
  "results": [
    {
      "index": 1,
      "uri": "/DEV/xyz-xyzRecord/OS1.json",
      "path": "fn:doc(\"/SIT1/xyz-xyzRecord/AB1.json\")",
      "score": 0,
      "confidence": 0,
      "fitness": 0,
      "href": "/v1/documents?uri=%2FDEV%2FIxyz-xyzRecord%2FOS1.json&database=data-hub-DEV",
      "mimetype": "application/json",
      "format": "json",
      "matches": null,
      "extracted": {
        "kind": "array",
        "content": [
          {
            "xyz": "AB1"
          }
        ]
      }
    },
    {
      "index": 2,
      "uri": "/DEV/xyz-xyzRecord/anc.json",
      "path": "fn:doc(\"/SIT1/xyz-xyzRecord/anc.json\")",
      "score": 0,
      "confidence": 0,
      "fitness": 0,
      "href": "/v1/documents?uri=%2FDEV%2FIxyz-xyzRecord%2FOS1.json&database=data-hub-DEV",
      "mimetype": "application/json",
      "format": "json",
      "matches": null,
      "extracted": {
        "kind": "array",
        "content": [
          {
            "xyz": "AB133"
          }
        ]
      }
    }
  ]
}

已尝试规格

[
  {
    "operation": "shift",
    "spec": {
      "results": {
        "*": {
          "@extracted.content": ""
        }
      }
    }
  }
]

低于输出

[
  {
    "xyz": "AB1"
  },
  [
    {
      "xyz": "AB113"
    }
  ]
]

但预期

[
  {
    "xyz": "AB1"
  },
  {
    "xyz": "AB133"
  }
]

相关问题