I'm currently working on the below JSON. Sometimes records in matches return null, instead of record. And null will appear anywhere within the array
{
"status": "success",
"error_code": null,
"matches": [
{
"status": "success",
"error_code": null,
}
,null,
{}]
}
Apex code:
if(jsonResponse.contains(',null,'))
{
jsonResponse = jsonResponse.replaceAll(',null,', ',{"id": ""},');
}
if(jsonResponse.contains('null\\,{'))
{
jsonResponse = jsonResponse.replaceAll('null\\,{', '{"id": ""},{');
}
if(jsonResponse.contains('null\\]'))
{
jsonResponse = jsonResponse.replaceAll('null\\]', '{"id": ""}]');
}
Please guide me on how to replace null with array #Json #Apex #Trailhead