Converting SQL XML CASE statement to SQL JSON

Viewed 26

Need assistance to convert SQL query with xmlelement containing a case statement to JSON.

case 
     when db_field1 = '1' then
          xmlelement(name "value", 'response1')
     when db_field2 - '2' then
          xmlelement(name "value", 'response2')
     else 
          xmlelement(name "value", '')
end

Tried something like this:

json_object (
    case 
         when db_field1 = '1' then
              'value' is 'response1'
         when db_field2 - '2' then
              'value' is 'response2'
         else 
              'value' is null
    end
)
1 Answers

Solved:
JSON syntax is in the format off "key": "value" so this is the correct way. In this example information is the field to store this data.

json_object (
    'information' is 
         case when db_field1 = '1' then 'response1'
              when db_field2 - '2' then 'response2'
         else null
         end 
      )
Related