0

I was trying extract value in SQL developer from below json but it gives me wrong output

select
json_value('{"ABC": {
    "CFF": 90,
    "coord": {
      "x1": 27.4,
      "x2": 31.6,
      "y1": 61.4,
      "y2": 62.4
    },
    "value": "\\"
  }}','$."ABC".value') COL from dual

enter image description here

Kindly suggest ..

Amol
  • 429
  • 4
  • 22

1 Answers1

1

The backslash symbol \ is also an escape character - so \\ in a quoted string "\\" becomes a single unescaped \

If you want the value to be \\ you have to double the amount of backslashes to \\\\

Daniel
  • 10,641
  • 12
  • 47
  • 85
  • Well data is coming from different system, We need to extract as it is. – Amol Aug 12 '22 at 11:48
  • In that case the different system has to double the amount of backslashes when inserting the data into the database. The value in the database is missing the `\` if it is unescaped – Daniel Aug 12 '22 at 11:56
  • 2
    As Daniel said, the \ is defined by JSON standard (not Oracle) as an escape character, with \\ meaning just one \. If you insert the string there in a 19c database, with a column defined as varchar2, it will have "\\" in there, but when you apply json functions, the string will be parsed and what the JSON standard says applies. – gsalem Aug 12 '22 at 15:48