ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Using json_arrayagg() to return list of values without names

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

  • Using json_arrayagg() to return list of values without names

    How do I use db2 sql to generate a list of values without names?

    PHP Code:
    {
      
    "name" "value",
      
    "myarray" : ["value1","value2","value3"]


  • #2
    It took me a while to figure it out.

    PHP Code:
    select
        json_object
    (
            
    'name' value 'value',
            
    'myarray' value json_arrayagg(
                  
    mycolumn
            
    )
        )
    from mytable
    where mykey 
    keyvalue
    group by mykey 

    Comment


    • #3
      Oh, I see... you wanted all values of a column to be reported as an array within the json document.

      Comment

      Working...
      X