0


I have a JSON structure, which is small.
My requirement is to expand the JSON structure.

Example JSON structure :

'{  
   "CallLog":{  
      "Three":{  
         "age":100,
         "name":"Sample",
         "Other":100,
         "Add":"Sample"
      },
      "One":{  
         "CallLogEntry":[  
            {  
               "ContryCode":{  
                  "CountryCode":123
               }
            },
            {  
               "Phone Number":{  
                  "PhoneNumber":456
               }
            },
            {  
               "Name":{  
                  "name":456
               }
            }
         ]
      },
      "Two":{  
         "age":100,
         "name":"Sample",
         "Other":100,
         "Add":"Sample"
      }


     }
    }


So, i want to expand his JSON.
Lets say i want repeat "One" node 10 times, and "two" node 5 times, and then write this expanded JSON in the new JSON.
How can i do this?

mayank bisht
  • 618
  • 3
  • 14
  • 43
  • 1
    Can you write out in your question an example of the desired result? I'm not 100% sure if I understand but I think it's not possible to do since you would have duplicate keys http://stackoverflow.com/questions/5306741/do-json-keys-need-to-be-unique – MalcolmInTheCenter Mar 19 '17 at 17:24
  • parse the json, use the parsed object to fill a new object with desired additions, serialize the new object to get the new json. (something like that) –  Mar 19 '17 at 17:27
  • @RC. How can i do that. ? – mayank bisht Mar 19 '17 at 17:31
  • @altoids { "CallLog": { "One": { "CallLogEntry": [ { "ContryCode": { "CountryCode": 123 } }, { "Phone Number": { "PhoneNumber": 456 } }, { "Name": { "name": 456 } }, { "ContryCode": { "CountryCode": 123 } }, { "Phone Number": { "PhoneNumber": 456 } }, { "Name": { "name": 456 } } ] } } } – mayank bisht Mar 19 '17 at 17:34
  • what java json library are you using? – MalcolmInTheCenter Mar 19 '17 at 17:39

1 Answers1

0

If you want to do it through java, i would recommend converting this JSON to java code first.Once you get the corresponding classes e.g. CallLog.java,CallLogEntry.java etc , you can define a new Class CallLog1.java and declare 10 'One' , 5 'Two' etc , as per your requirement and then create the JSON object. You can copy paste your json to http://www.jsonschema2pojo.org/ to get POJO , and then create you own POJO , and convert it into JSON , using library like GSon.

Jason1
  • 101
  • 4