https://kotlinlang.org logo
r

Ryunos

10/05/2022, 3:54 PM
Hi, is there a way to parse a string containing JSON to a list of associations key to value? I would like to check for duplicate keys in a JSON using such a list so a Map would not help me
j

jw

10/05/2022, 4:20 PM
Ask for a
Map<String, Any>
as your type
r

Ryunos

10/06/2022, 7:16 AM
I would like to check duplicate keys so a Map would not help me but it does answer my initial question 😅
j

jw

10/06/2022, 1:51 PM
There's an arbitrary JSON type called
JsonObject
I think. No idea what it does with duplicate keys.
r

Ryunos

10/06/2022, 1:52 PM
Ok, I’ll take a look at that type. I’ll tell you if I found something that solves my problem!
j

jw

10/06/2022, 1:52 PM
You could also write a sneaky custom
Map
subtype that retained duplicate key/values and exposed them through some side-channel.
Although you'd need a custom serializer that created that sneaky map
r

Ryunos

10/06/2022, 1:53 PM
Thank you for your answers 🙂
7 Views