2

I have this form of data below and I want to convert it into json using java

The problem that the string contains brackets for objects and numbers which means the array ordering...

status=accepted&results[0][id]=7&results[0][name]=data&results[0][score]=9&results[1][name]=data2&results[1][score]=7&results[1][id]=8&reports[0][name]=data1&reports[0][id]=1&reports[0][is_available]=1&reports[1][id]=2&reports[1][name]=data&email=test@test.com

Thanks

slama
  • 85
  • 2
  • 11
  • How your getting this data ? And please post your attempts here. – Sudhir Ojha Nov 04 '19 at 12:29
  • Maybe one of these [solutions](https://stackoverflow.com/q/13592236/8547799) will do the trick. – Tns Nov 04 '19 at 12:38
  • @SudhirOjha I get this data as an input from an external API, my attempts doesn't work no need to post here, I tried to create an object and get this String as object in requestBody but doesn't work cause of brackets, and if i will split an do the conversion manually it will take some lines of code, so i'm asking if there is another way... – slama Nov 04 '19 at 13:40

1 Answers1

1

If the pattern is fixed, Regular expressions can be used to check the pattern and replace to form JSON.

Check Pattern Replace

Might have to code, depending upon the use case.

E.g., if 2D array elements like results[0][id] have to be converted

{ "results": { "id": 7, "name": "data" } }

Nagendra
  • 51
  • 4