1
votes

I have the following JSON structure and I would like to extract the 3 from the value from context containing All UpdateCounter's. The following is what I have tried and it didn't work:

$.counters.aggregateSnapshot.counters.[context=="All UpdateCounter\'s"].valueCount

What could be the possible NIFI expression?

2

2 Answers

2
votes

1 - SplitJson - on $.Conters 2 - EvaluateJsonPath

$.id

$.context

$.name

$.valueCount

$.value

3 - RouteonAttribute

route rule:

${context:contains('All UpdateCounter\'s')}

or

${context:equals('All UpdateCounter\'s')}

4 - extract Text - if you want it like a csv

${id},${context},${name},${valueCount},${value}

1
votes

Even though this is an old question, future readers could benefit: what about JoltTransformJSON? It uses only one processor and returns what you need:

Jolt Transformation DSL: Shift

Jolt Specification:

[
  {
    "operation": "shift",
    "spec": {
      "counters": {
        "aggregateSnapshot": {
          "counters": {
            "*": {
              "*": {
                "context": {
                  "All UpdateCounter's": {
                    "@3": "results"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

Result:

{
  "results" : {
    "9" : {
      "id" : "xxxxxxx",
      "context" : "All UpdateCounter's",
      "name" : "flag",
      "valueCount" : 3,
      "value" : "3"
    }
  }
}

Tested using: Jolt Transform Demo with these settings (the web app won't let me permalink the example, so here's an image):

enter image description here