0

I am getting the below records from a backend system and not sure how many such records I might be receiving. As you can see the data I receive is not in a valid json format.

[489078:{cancelled:1, totalQty:2, AcceptedQty:1}, 
489079:{cancelled:0, totalQty:1, AcceptedQty:1},
.
.]

I want to convert the above payload into a valid a JsonArray of JsonObjects for further processing by converting it into a String first. I've tried replace String function, but it always fails at some point. Is there any other approach supported by java for performing this function?

Ruby
  • 368
  • 1
  • 9
  • You need to fix the problem at the source, by asking the source to provide you JSON. To be clear, this is not "invalid JSON", it is simply not JSON at all (likely it is a concoction of default `toString()` of collections or something). Alternatively, you need to write your own custom parser, either rewriting it to JSON or directly to objects, neither of which is simple to do (and would require this to be actually be a stable and specific format, which is unlikely), and really too broad for a question on Stack Overflow – Mark Rotteveel Apr 14 '23 at 08:26
  • You wrote: _I am getting the below records from a backend system_ Are you getting them as a single string? You also wrote: _I want to convert ... it into a String_ Can you [edit] your question and post the string you wish to get? _I've tried replace String function, but it always fails at some point._ Can you post the code that you tried and details of the failure? – Abra Apr 14 '23 at 11:46

0 Answers0