Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to get specific fields from Json in Nifi JoltTransformJson?

avatar
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

avatar
Contributor

I solved the problem. I used this solution;

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

View solution in original post

1 REPLY 1

avatar
Contributor

I solved the problem. I used this solution;

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