I am having trouble deserializing the JSON request received.
Below is the JSON format I receive,
{
header:{
worker count: 2},
Worker:{
name:emp1
},
Worker:{
name:emp2
},
Worker:{
name:emp3
}
}
With the below code, I tried to put them in the array -
string jsonstring = request.requestbody.tostring();
string regex = ',\\"([^\\"]+)\\"\\:+\\{'; // regex for ,"worker" :{
String resultStr = JSONreqstring.replaceFirst(regex, ',"Workers": [{'); //replace first occurance of "worker" with start of the workers array
String resultStr1 = resultStr.replace('"Worker":{', '{'); // remove subsequent worker and put them in the array
String resultStr2 = resultStr1.removeEnd('}');
resultStr3 = resultStr2 + ']}';
The resultstr3 would be -
{
header:{
worker count: 2},
Workers:[{
name:emp1
},
{
name:emp2
},
{
name:emp3
}]
}
Then I am able to deserialize this, the problem is, if the json request has more number of records, i get the regex too complicated error as salesforce has 1M character limit on the string for comparision.