Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help on retrieving JSON attributes from a flow file in Apache NiFi

I'm trying to get the attribute values from a JSON file using EvaluvateJsonPath processer in NiFi.

Below is the sample JSON file

{"widget": {
    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    },
    "image": { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    },
    "text": {
        "data": "Click Here",
        "size": 36,
        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,
        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
    }
}}

Below is my configuration.

Configuration

The expected output should be "main_window". But i'm getting the whole JSON string as the output. Can someone please point me in the right direction, what went wrong here?

Update:

This is the flow file content, i'm seeing in the queue as an outcome of EvaluvateJsonPath processer.

enter image description here

like image 551
Sathyaraj Avatar asked Jun 16 '17 09:06

Sathyaraj


People also ask

Which of the following are attributes of Apache NiFi?

The most common attributes you'll see are filename , path and uuid . The string in parentheses is the value of the attribute within the CoreAttributes enum and how it appears in the UI/API. Filename ( filename ): The filename of the FlowFile.

Where are flow files stored NiFi?

Data of the flowfiles is stored in 3 directories on disk, flowfile repository - persists attributes of the flowfile. content repository - stores all data contained in the flowfile. provenance repository - stores information about the history of the flowfile.

How do I update attributes in NiFi?

As an example, to alter the standard "filename" attribute so that it has ". txt" appended to the end of it, add a new property and make the property name "filename" (to reference the desired attribute), and as the value, use the NiFi Expression Language statement shown below: Property: filename. Value: ${filename}.


1 Answers

You have given "Name"-->$.widget.window.name correctly.

But you have to specify "ReturnType"-->json not to be "ReturnType"-->autodetect.

That's the problem for you have received whole json string.

EDIT-1

If you change return type to be json then you can receive your expected output "main_window"` to be stored in Attribute ${Name}.

After that you can use ReplaceText processor to Specify replacement value "${Name}" then you can receive "main_window" in flowfile

It could be worked for me.

And Let me know if you face any issues

like image 163
Mister X Avatar answered Oct 12 '22 16:10

Mister X