3

I have a large JSON response where I only need to update certain fields. Want to filter down the response, but the key/value pair I'm interested in is nested at varying levels. I tried to use the jsonpath .. notation to find it.

* eval var testcaseArray = response.collection.item.filter(o => o..name.includes(/^(RD-T|RES-T)/));

But the second ellipses is not recognized as valid Javascript syntax.

org.graalvm.polyglot.PolyglotException: SyntaxError: Unnamed:1:59 Expected ident but found .
var testcaseArray = response.collection.item.filter(o => o..name.includes(/^(RD-T|RES-T)/))
anutter
  • 366
  • 2
  • 17

1 Answers1

0

Unfortunately JSON "update" operations will require you to explicitly know the keys and the hierarchy. The JsonPath things such as * and .. won't work.

You could try a brute-force regex based find-and-replace on the JSON and then re-convert it to JSON, but I would not recommend that.

I think it will be possible to recurse all JSON key-value pairs and do this, let me see if I can figure this out and update here later.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248