Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

$..*

like image 998
meh Avatar asked Jun 11 '26 15:06

meh


2 Answers

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

like image 166
daggett Avatar answered Jun 14 '26 05:06

daggett


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

like image 42
M.Selman SEZGİN Avatar answered Jun 14 '26 04:06

M.Selman SEZGİN