Need help with decoding malformed JSON missing double quotes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Need help with decoding malformed JSON missing double quotes

Post by zeus1 »

I have malformed JSON; it is missing double quotes for every entry. Is there a way to decode it as is, or a function I can use to add double quotes to every entry efficiently?
Last edited by zeus1 on Mon Oct 18, 2010 9:48 pm, edited 2 times in total.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Need help with decoding malformed JSON missing double qu

Post by Eran »

Hi Zeus, please use [syntax] tags in the future to prevent a very large scroll to the page.

Regarding your question, how did you generate this JSON string? if you are using PHP you can use the json_encode() function that will correctly prepare your data as valid json.
http://php.net/manual/en/function.json-encode.php
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Re: Need help with decoding malformed JSON missing double qu

Post by zeus1 »

Sorry about that. It's from another source.
Last edited by zeus1 on Mon Oct 18, 2010 9:30 pm, edited 1 time in total.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Need help with decoding malformed JSON missing double qu

Post by Eran »

You can use the PEAR package Service_Json to clean up your string. Decode the string and then encode it again and it will create a valid JSON string.
http://pear.php.net/pepr/pepr-proposal-show.php?id=198
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Re: Need help with decoding malformed JSON missing double qu

Post by zeus1 »

***SOLVED***

Thanks, Eran!
Post Reply