JSON.parse with double quotes in String

2,245 views
Skip to first unread message

Rusco

unread,
Sep 13, 2012, 10:39:23 AM9/13/12
to phan...@googlegroups.com

I am trying to handle over some data (which I get from a database and convert with C# to Json) to Phantomjs as Json String.
That means I have no influence on the content of the data (I have to accept the double quotes as they come).

PhantomJs refuses to Parse some data which have double quotes in its string.

As a short example:

Phantomjs: var i = "ab\"c"; //throws parseError, i is undefined
Nodejs/Recent Browser: var i = "ab\"c";   //ok, i = 'ab"c';


Did anybody already stumble over this issue ?

I already saw some related discussion here:
http://ariya.ofilabs.com/2012/02/from-double-quotes-to-single-quotes.html




Ariya Hidayat

unread,
Sep 13, 2012, 10:42:40 AM9/13/12
to phan...@googlegroups.com
This is so easy to test I don't know what kind of logic error do you
have. Create a script test.js containing these 3 lines:

var i = "ab\"c";
console.log(i);
phantom.exit();

Running:

phantomjs test.js

gives me exactly what I want. No error.



--
Ariya Hidayat, http://ariya.ofilabs.com
http://twitter.com/ariyahidayat

Ariya Hidayat

unread,
Sep 13, 2012, 10:43:34 AM9/13/12
to phan...@googlegroups.com
> I already saw some related discussion here:
> http://ariya.ofilabs.com/2012/02/from-double-quotes-to-single-quotes.html

How's that blog post related to this issue(beside the fact that it
mentions quotes) is a mystery to me.

j.rebhan

unread,
Sep 13, 2012, 11:00:01 AM9/13/12
to phan...@googlegroups.com, ariya....@gmail.com
Hi Ariya,

could you try that on the phantomjs console:

phantomjs> var i = "ab\"c";

I get: "SyntaxError: Parse Error" (phantom 1.6.1 on Win7).

Is there a different behavior on the command - line vs. script mode ?

Thanks

Rusco

PS: Your blogpost is not related to my problem at all.....




2012/9/13 Ariya Hidayat <ariya....@gmail.com>
--




Rusco

unread,
Sep 13, 2012, 11:55:24 AM9/13/12
to phan...@googlegroups.com
The complete example is here:

https://gist.github.com/3715242


I wonder whether someone already tried to pass over some Json on the commandline to Phantomjs, on Node it seems to be pretty common.

Your blogpost uses a cleanup script, I probably have to write something like that as workaround.

Ivan De Marino

unread,
Sep 13, 2012, 1:09:25 PM9/13/12
to phan...@googlegroups.com
Most probably something wrong in the way the REPL parses the input.

Unfortunately that things needs some love to iron out those problems and I haven't got time since I work on GhostDriver.


--
 
 
 



--
Ivan De Marino
Coder, Technologist, Cook, Italian

blog.ivandemarino.me | www.linkedin.com/in/ivandemarino | twitter.com/detronizator
Reply all
Reply to author
Forward
0 new messages