Suppose you have some kind of JSON as follows:
{
"students" : [
{
"id" : "01",
"name" : "Tom",
"lastname" : "Price",
"hobbys" : [ "football", "hockey" ]
},
{
"id" : "02",
"name" : "Nick",
"lastname" : "Thameson",
"hobbys" : [ "reading", "gardening", "painting" ]
}
]
}
and I would like to create a list attribute for only some specific content of the JSON. For example, lets say your only interested in only the name and lastname of the students. Then I would like to achieve a result like:
students{0}.name = Tom
students{0}.lastname = Price
students{1}.name = Nick
students{1}.lastname = Thameson
Is there some easy way to achieve that?
I am aware of the following transformers that can extract JSON data:
- JSONExtractor
- JSONFlattener
- JSONFragmenter
However, for the JSONExtractor I'm only familiar with the possibility to create attributes for (single) JSON objects or a specific JSON array element. Is there maybe some option in the JSONExtractor that I'm unaware of in which you can set list attributes for (specific elements of) a JSON array?
Using the JSONFlattener I find myself that the entire JSON is being flattened, so then I always find myself first using a JSONExtractor to extract specific content to flatten, exposing the (expected) flattened attributes, and removing all other undesired attributes using AttributeKeepers, -Removers or -Managers.
Somewhat similarly using an AttributeFragmenter I find myself fragmenting the JSON array of interest into individual features for each element of the JSON array, extracting the desired JSON attributes, and then building the desired list.
I guess there are probably some options to achieve my goal using JSONiq (a kind of xQuery for JSON instead of XML) in an XMLXQueryExtractor transformer, but unfortunately I only vaguely know about JSONiq (basically that it exists and looks like xQuery), and have only limited experience with xQuery for XML.
Although I would be really interested to learn the possibilities of JSONiq for this purpose (maybe someone can share an example), where possible I would prefer to use 'non scripting' transformers to achieve my task.
But then again I'm afraid that using 'conventional transformers' would require multiple steps, and in that case I would still prefer a direct solution in JSONiq.
Curious to hear if others have some experience/ideas on this front.
Kind regards,
Thijs