ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How do you embed a json array string into a json_object without double quotes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do you embed a json array string into a json_object without double quotes

    I have a parameter to a program that contains a string of data containing a json array. I need to create a new json string using json_object() and within that json object, i need to insert the value of the parameter string (which again is a json array). It seems when I do it, the json string is encapsulated in quotes. How do I tell json_object to not put the value in quotes?

    PHP Code:
    select
      json_object
    (
        
    'request' value :@request
        
    'response' value 'some response'
      
    )
    from sysibm.sysdummy1
    @request looks something like this:

    PHP Code:
    [{'key':'value'},{'key':'value'}] 
    I don't want @request to treated as a json string. Is there a way to run @request through json_arrayagg() to return an array object?

  • #2
    Try
    Code:
    [COLOR=#000000][COLOR=#0000BB]select
      json_object[/COLOR][COLOR=#007700](
    [/COLOR][COLOR=#DD0000]'request' [/COLOR][COLOR=#0000BB]value [/COLOR][COLOR=#007700]:@[/COLOR][COLOR=#0000BB]request [B]format json[/B]
    [/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'response' [/COLOR][COLOR=#0000BB]value [/COLOR][COLOR=#DD0000]'some response'
    [/COLOR][COLOR=#007700])[/COLOR][/COLOR]
    Format json tells json_object() that @request is already valid JSON, so does not need to be encoded. I think.

    Comment


    • TheZenbudda
      TheZenbudda commented
      Editing a comment
      Yes! I was struggling to find that! Thank you!

    • Vectorspace
      Vectorspace commented
      Editing a comment
      You're welcome. But for anyone else, be aware that the XML version of this has no such feature, unfortunately.
Working...
X