Using Jolt to filter results

Viewed 41

Given the following input:

[
  {
    "order": "SI867-5309"
  },
  {
    "order": ""
  },
  {
    "order": "SI555-1212"
  },
  {
    "order": {
      "status": "Bad"
    }
  }
]

I want to use jolt to translate to :

[
  {
    "order": "SI867-5309"
  },
  {
    "order": "SI555-1212"
  }
]

I have gotten close with:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "order": {
          "SI*": "@1"
        }
      }
    }
  }
]

but thats not it, because it although it does filter out the values starting with SI, it then makes the values into the keys. I think I'm missing something obvious...

1 Answers

Yes, you're so close to the result, just replace "@1" with { "$": "[].&2" }

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "order": {
          "SI*": {
            "$": "[].&2"
          }
        }
      }
    }
  }
]

where "$" operator matches the key, &2 matches the value and prepending &2 with []. is used to seperate the elements respectively.

Related