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 get nested data from given data.?

Highlighted

How get nested data from given data.?

I have tried SplitJson and EvaluateJson processor in NiFi but i cant get proper data
exmple:

{
   "affiliate": {
	"name": "affiliate",
	"apiLists": {
		"category1": {
			"availableVariants": {
				"v1.1.0": {
					"resourceName": "category1",
					"put": null,
					"delete": null,
					"post": null
				},
				"v0.1.0": {
					"resourceName": "category1",
					"put": null,
					"delete": null
				}
			},
			"apiName": "category1"
		},
		"category2": {
			"availableVariants": {
				"v1.1.0": {
					"resourceName": "category2",
					"put": null,
					"delete": null,
					"post": null
				},
				"v0.1.0": {
					"resourceName": "category2",
					"put": null,
					"delete": null,
					"post": null
				}
			},
			"apiName": "category2"
		}
	}
   }	
}
i want to get that "category1" which is come in apiLists and also want to get "category2" but i cant get it by using SplitJson and EvaluateJson
2 REPLIES 2
Highlighted

Re: How get nested data from given data.?

Super Guru

I'm assuming you're looking to have the following results:

{
  "category1" : {
    "availableVariants" : {
      "v1.1.0" : {
        "resourceName" : "category1",
        "put" : null,
        "delete" : null,
        "post" : null
      },
      "v0.1.0" : {
        "resourceName" : "category1",
        "put" : null,
        "delete" : null
      }
    },
    "apiName" : "category1"
  },
  "category2" : {
    "availableVariants" : {
      "v1.1.0" : {
        "resourceName" : "category2",
        "put" : null,
        "delete" : null,
        "post" : null
      },
      "v0.1.0" : {
        "resourceName" : "category2",
        "put" : null,
        "delete" : null,
        "post" : null
      }
    },
    "apiName" : "category2"
  }
}

If so, you can use JoltTransformJSON with the following Chain spec:

[
  {
    "operation": "shift",
    "spec": {
      "affiliate": {
        "apiLists": {
          "category1": "&",
          "category2": "&"
        }
      }
    }
  }
]

If you don't know how many categoryX entries you'll have, you can use the following to get all of them:

[
  {
    "operation": "shift",
    "spec": {
      "affiliate": {
        "apiLists": {
          "category*": "&"
        }
      }
    }
  }
]
Highlighted

Re: How get nested data from given data.?

@Matt Burgess
Thank you sir. But What should i do if i don't know the name of category or i don't want to write name of particular category and want to get category loop wise (like one by one)..?

Actually i have many categories and want to store these categories into hbase one by one (for example store category1 in one row with it's unique row identifier. That's why i want to get categories one by one

Don't have an account?
Coming from Hortonworks? Activate your account here