I looking at the code on how to generate a JSON structure like below:
1. {
"element1": "123123",
"element2": "test",
"element3": [{
"element3.1": " ",
"element3.2": " ",
"element3.3": " ",
"element3.4": " ",
"element3.5": " "
}],
"element5": "01",
"element6": "123333",
}
On researching I am able to find out the way to generate JSON for element 1 and 2 but I want some help to know how to generate JSON structure for element 3 onwards.
So far I tried this :
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField('element1', 123123);
gen.writeStringField('element2', test);
// How to generate element3 structure?
gen.writeEndObject();
How do I go about if the structure starts with an array?
{
"elementAA": [{ "element1": "123123", "element2": "test", "element3": [{ "element3.1": " ", "element3.2": " ", }], "element5": "01", "element6": "123333" }] }