You need to sign in to do that
Don't have an account?

Serialize String to JSON
I have a String which I need to convert and make it look the below in JSON.
I want to convert the String s to JSON, Please help
String allIndexes = 'Columns/Sections :1, Columns/Sections :2';
String s = 'error: "SECTION_LENGTH_EXCEEDED",' +'\n'+'message: Unable to save RuleAction record, HTML content size is bigger that expected ' +'\n'+'erroredSections : '+ allIndexes;
EXPECTED OUTPUT JSON FORMAT :
JSON : {
error: "SECTION_LENGTH_EXCEEDED",
message: "Unable to save sections, json object size is bigger that expected",
erroredSections: [
{ Columns/Sections :1 }
{ Columns/Sections :2 }
]
}
}
I want to convert the String s to JSON, Please help
String allIndexes = 'Columns/Sections :1, Columns/Sections :2';
String s = 'error: "SECTION_LENGTH_EXCEEDED",' +'\n'+'message: Unable to save RuleAction record, HTML content size is bigger that expected ' +'\n'+'erroredSections : '+ allIndexes;
EXPECTED OUTPUT JSON FORMAT :
JSON : {
error: "SECTION_LENGTH_EXCEEDED",
message: "Unable to save sections, json object size is bigger that expected",
erroredSections: [
{ Columns/Sections :1 }
{ Columns/Sections :2 }
]
}
}
You can create a wrapper for your json and then use that wrapper to create the object as you want and then serialise it. It will give you exact json as you want.
Wrapper may look something like this :
Thanks