views:

39

answers:

1

Hi,

I have a problem with the regex of Zend_Json::prettyPrint. When in my JSON response I have a string with a comma inside like

"stack, overflow" 

the string is splited in two:

"stack,
overflow"

and I would like to have the string on the same line and not splited. In the file Zend/Json I found the regex:

$tokens = preg_split('|([\{\}\]\[,])|', $json, -1, PREG_SPLIT_DELIM_CAPTURE);

I don't arrive to correct the regex to avoid the split when there is a comma inside the double quote.

Here is the JSON for the test:

{ "test":"stack, overflow" }

I hope somebody will be able to help me.

Thanks in advance,

Maxime.

A: 

Ok, So I found a solution not a real clean solution but it works. I would like to do it with regular expression in the future.

I just count the number of double quotes without the double quotes escaped, and when the number of quotes are pair and the split is a comma, I add a line break.

You can watch the helper here: http://gist.github.com/483311

Maxime P