[Q] storing JSON, problem with 'escapes'

From: "V S P" <toreason(at)fastmail(dot)fm>
To: pgsql-php(at)postgresql(dot)org
Subject: [Q] storing JSON, problem with 'escapes'
Date: 2008-11-21 06:54:35
Message-ID: 1227250475.15555.1285991741@webmail.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

Hi,
I am using PHP's json_encode function on
an array of strings
that gives me back a JSON encoded string.

Some of the elements in the string arrays have
double quotes. So PHP's json_encode correctly
escapes them (according to JSON specifications)
with \.

For example here is a an array element

"if( js_iop_lt(a,b) ){ VLADIKVLADIKVLADIKVLADIK("b2122") ;}"

would get encoded in JSON as

"if( js_iop_lt(a,b) ){ VLADIKVLADIKVLADIKVLADIK(\"b2122\") ;}"

And that's correct.
Now, the problem is that with PDO (or may be postgresql itself)
I get

"if( js_iop_lt(a,b) ){ VLADIKVLADIKVLADIKVLADIK(\\"b2122\\") ;}"

and I get then the POSTGRESQL warning

WARNING: nonstandard use of \\ in a string literal at character 240
HINT: Use the escape string syntax for backslashes, e.g., E'\\'.

( I am seeing what postgres is getting because I enabled logging of
all the statements to stderr)
--------

So I am not sure what to do. This has to be a common issue
(unless nobody before me stored JSON in postgresql :-) ).

The PDO does not provide facilities to 'not to escape' or escape
differently.

Ideally I do not want the second backslash. I do not undestand who
adds it and why. The first backslash is by json_encode -- which is
correct.

thanks in advance for any help.

--
V S P
toreason(at)fastmail(dot)fm

--
http://www.fastmail.fm - Access all of your messages and folders
wherever you are

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Chris 2008-11-21 07:17:59 Re: [Q] storing JSON, problem with 'escapes'
Previous Message V S P 2008-11-17 08:55:55 Re: [Q] PDO use to bind arrays for insert