Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to get specific fields from Json in Nifi JoltTransformJson?

Solved Go to solution

How to get specific fields from Json in Nifi JoltTransformJson?

Contributor

I have nifi cluster summarry json data like this;

[{
	"nodeId": "29bed24c-6d73-4652-930b-0065cad4ef66",
	"address": "b1518aec7e38",
	"apiPort": 8080,
	"status": "CONNECTED",
	"heartbeat": "01/16/2019 16:24:32 UTC",
	"roles": ["Primary Node", "Cluster Coordinator"],
	"activeThreadCount": 0,
	"queued": "0 / 0 bytes",
	"events": [{
		"timestamp": "01/16/2019 15:21:50 UTC",
		"category": "INFO",
		"message": "Received first heartbeat from connecting node. Node connected."
	}, {
		"timestamp": "01/16/2019 15:21:48 UTC",
		"category": "INFO",
		"message": "Connection requested from existing node. Setting status to connecting."
	}],
	"nodeStartTime": "01/16/2019 15:20:44 UTC"
   },
   {
	"nodeId": "22aofpp4-87rf-asf4-930b-0065cad4ef66",
	"address": "b67uf98tkl5",
	"apiPort": 8080,
	"status": "CONNECTED",
	"heartbeat": "01/16/2019 16:24:32 UTC",
	"roles": [],
	"activeThreadCount": 0,
	"queued": "0 / 0 bytes",
	"events": [{
		"timestamp": "01/16/2019 15:21:50 UTC",
		"category": "INFO",
		"message": "Received first heartbeat from connecting node. Node connected."
	}, {
		"timestamp": "01/16/2019 15:21:48 UTC",
		"category": "INFO",
		"message": "Connection requested from existing node. Setting status to connecting."
	}],
	"nodeStartTime": "01/16/2019 15:20:44 UTC"
}]

I want only nodeId and status fields from this json. Output what i want;

{
   "nodeIds": ["node1Id", "node2Id"],
   "status": ["node1Status", "node2Status"]
}

For example output what i want;

{
   "nodeIds": ["29bed24c-6d73-4652-930b-0065cad4ef66", "22aofpp4-87rf-asf4-930b-0065cad4ef66"],
   "status": ["CONNECTED", "CONNECTED"]
}

But I couldn't do Jolt Specification for this. How can i do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How to get specific fields from Json in Nifi JoltTransformJson?

Contributor

I solved the problem. I used this solution;

[
  {
    "operation": "shift",
    "spec": {
    	"*": {
        	"nodeId": "node_ids",
          	"status": "node_status"
        }
    }
  }
]
1 REPLY 1
Highlighted

Re: How to get specific fields from Json in Nifi JoltTransformJson?

Contributor

I solved the problem. I used this solution;

[
  {
    "operation": "shift",
    "spec": {
    	"*": {
        	"nodeId": "node_ids",
          	"status": "node_status"
        }
    }
  }
]
Don't have an account?
Coming from Hortonworks? Activate your account here