meh
meh

Reputation: 273

Extracting Value from Nested JSON in Apache NiFi

I have escaped JSON dataflow from the ConvertAvroToJSON processor, which looks like this:

{"data": "{\"created_at\":\"Sun Sep 24 11:10:52 +0000 2017\"}"}

I need to extract the "json" value so that it looks like this after unescaping:

{"created_at":"Sun Sep 24 11:10:52 +0000 2017"}

I tried using JoltTransformJSON and EvaluateJsonPath, but both methods return this, with {" and "} at the beginning and end:

{"{"created_at":"Sun Sep 24 11:10:52 +0000 2017"}"}

What should I do to correctly extract the JSON value?

Jolt Spec:

[{   "operation": "shift",   "spec": {
    "data": {
      "*": "&"
    }   } }]

EvaluateJsonPath:

$..*

Upvotes: 3

Views: 4633

Answers (2)

M.Selman SEZGİN
M.Selman SEZGİN

Reputation: 313

You need 2 steps. First, extract inner json to your flow content. After that you can access json attributes from this json flow content.

First Step: First Step

Second Step Second Step

Flow View

Flow view of this actions

Upvotes: 2

daggett
daggett

Reputation: 28634

use EvaluateJsonPath with $.data expression

if you have {"data": "{\"created_at\":\"Sun Sep 24 11:10:52 +0000 2017\"}"} in the content of your flowfile

it will replace the content with the following data:

{"created_at":"Sun Sep 24 11:10:52 +0000 2017"}

here are all the parameters of the processor

enter image description here

Upvotes: 3

Related Questions