1

How can I clean Dirty JSON String format ?

For Example from this String

{"AS_applicant_Data__c":"{\\\"Full Name\u00a0\\\":\\\"asdffas\\\"}"}

to this format

{"AS_applicant_Data__c":"{"Full Name":"asdffas"}"}
3
  • You could use substr_replace? php.net/manual/en/function.substr-replace.php Commented Dec 3, 2015 at 6:29
  • I would have tried stripslashes, but you have \u00a0 in the original string. Where did you get this string? Commented Dec 3, 2015 at 6:42
  • its from json object that has spaces (original object{"Full Name ":"asdffas"}).. then when I convert it to json string .. the white spaces turns into unwanted characters. Commented Dec 3, 2015 at 6:48

1 Answer 1

2

Use str_replace to remove all occurrences of \ and u00a0 from your json string, like this:

echo str_replace('u00a0', '', str_replace('\\', '', $json_string));

Output:

AS_applicant_Data__c":"{"Full Name":"asdffas"}"}  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.