0

I don't know, whether it's possible at all, but here is my problem. This is a JSON containing an array without keys:

{
  "SearchResults": {
    "tables": [
      {
        "rows": [
          [
            "InternalExecutionError",
            "An internal execution error occurred. Please retry later.",
            "node-prod6",
            4
          ]
        ]
      }
    ]
  }
}

I need to extract node-prod6 using JSONPATH.

In this particular case $.SearchResults.tables[0].rows[0][2] will do the trick, but the problem is, that I don't know in advance the number rows or their order. All I know, that .SearchResults.tables[0].rows[0] contains the string I need somewhere. However I know the pattern of what I am looking for: node-*, so RegEx seems to be the best way, but is it possible to do RegEx matching in JSONPATH in an array without keys? If no, thank you for confirming, if yes, please, help with the syntax.

AlexeyO
  • 44
  • 3
  • Not sure you can do it with jsonpath, but it can be done with jq. – Jack Fleeting Jul 10 '20 at 19:41
  • 1
    Nope, can't be done with jsonpath. – tom redfern Jul 11 '20 at 20:04
  • Thank you, I suspected that much and now looking at the application, that generates this JSON output to make the format more predictable. – AlexeyO Jul 12 '20 at 09:21
  • Why not just change the tool you use? There is jq, Jmespath, jsonic, a few others. – Jack Fleeting Jul 12 '20 at 10:23
  • As often happens I'm not free in selecting the tool - I need to use whatever is available in the platform I work with. No big mystery in the scenario: one monitoring system fires alerts and sends them as json objects to another support incident management system. I want to customize the way the information is presented in the latter system, but all I can do is what possible to do with JSONPATH - that's the only tool the support incident management system has to offer. – AlexeyO Jul 12 '20 at 11:12
  • In that case you are really stuck :( You're right - the only thing to do is to convince whoever is in charge of formatting the alert to change the format so it's compatible with jsonpath filtering... – Jack Fleeting Jul 12 '20 at 11:19

0 Answers0