0

My Question seems very similar to this question, but what happens if the are duplicate values in the json file?

The duplicate values are found in the json file due to the file contents originating from postgres which allow to insert duplicate values in older JSON format files.

My input look like this.

 {
"61":{"value":5,"to_value":5},
"58":{"r":0,"g":0,"b":255}, "58":{"r":165,"g":42,"b":42},"58:{"r":0,"g":255,"b":0},
"63":{"r":0,"g":0,"b":0},
"57":{"r":0,"g":0,"b":255},"57":{"r":0,"g":255,"b":0}
}

If you look carefully there are multiple values of "58" as keys. The main keys "61" and "58" are mappted to a nested map type with different keys.

Now to simplify what I want to achieve, my output of the above input json should look like this.

Approach or solution both equally appreciated in java only.

 {
"61":[5,5],
"58": [{"r":0,"g":0,"b":255},{"r":165,"g":42,"b":42},{"r":0,"g":255,"b":0}],
"63":[{"r":0,"g":0,"b":0}],
"57":[{"r":0,"g":0,"b":255},{"r":0,"g":255,"b":0}]
}
Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42
user2903536
  • 1,716
  • 18
  • 25

1 Answers1

0

A good tool for parsing JSON formats is this library: JSONObject

Here an example of usage in a previous SO question: Parsing JSON which contains duplicate keys

Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42
ricgra
  • 1
  • 1