psql - Retrieving json data that contains special characters -
it looks psql db contains badly formatted json fields, hence cannot retrieve data using ->> operators.
i have table column "reputation" of type json.
i perform query "reputation" column specific object:
select reputation hashes sha1='c1b5684e132a85d18a35ddb98233cc2b71efcf0e'
i receive following result looks json formatted escape characters:
"{\"status\": \"malicious\", \"scanner_match\": 33, \"first_seen\": \"2010-05-27t09:00:27\", \"scanner_count\": 34, \"last_seen\": \"2010-05-27t09:00:27\"}"
however, when i'm trying specific field in json, receive nothing:
select reputation->>status hashes sha1='c1b5684e132a85d18a35ddb98233cc2b71efcf0e'
i tried following query check how psql handles json , received error:
select * json_each((select reputation hashes sha1='c1b5684e132a85d18a35ddb98233cc2b71efcf0e')); error: cannot deconstruct scalar
so looks psql not recognize json. if so, have couple of questions:
- if invalid json format, how possible psql allows insert badly formatted json json type column?
- is possible somehow access these json fields in existing state (maybe using special characters in names)?
its backslashes. psql see them escape characters , insert json data type no problem.
view in sql string seen string , not json, need perform string functions remove erroneous characters.
with cte as( select cast ('"{\"status\": \"malicious\", \"scanner_match\": 33, \"first_seen\": \"2010-05-27t09:00:27\", \"scanner_count\": 34, \"last_seen\": \"2010-05-27t09:00:27\"}"'as json) string) select cast(ltrim(rtrim(replace(cast(string text),'\',''),'"'),'"')as json) cte
this returns json datatype
Comments
Post a Comment