Home > Mobile >  How to decode an invalid stringified JSON - Flutter
How to decode an invalid stringified JSON - Flutter

Time:06-17

This Stringified JSON array is invalid because the map keys and values are not in quotes but I wanna decode it:

"[{division: bacteriology, speciality: microbiology, tests: [appearence of urine], category: urine}]"

CodePudding user response:

as your string is not in proper json format, so i try to decode this particular string by converting it to proper json-

String data = "[{division: bacteriology, speciality: microbiology, tests: [appearence of urine], category: urine}]";
    String formattedDataInJson = data.replaceAll("{", "{\"").replaceAll("}", "\"}").replaceAll(":", "\":\"").replaceAll(",", "\",\"").replaceAll("\"\"", "\"");
    String division = jsonDecode(formattedDataInJson)[0]["division"];

CodePudding user response:

If you are looking for an online tool, you could use this enter image description here

  • Related