withJson() with mixed data

Hi all,

I’m using mysql partially as a document store (some data is stored with usual varchar/int columns, some in a json column). Querying the database results into an array containing usual values and a one or two json documents - a simple example of a single row result would be:

$res[0] = [ 'id' => 1, 'owner' => 475, 'config' => '{ "token": "something" }' ]

now, if I return->withJson($res), i get the json coming from the database escaped.

{ 
  "status":"Success",
  "code":200,"data": [    
    { 
       "id":1,
       "owner":475,
       "config":"{\"token\": \"something\"}",
    }
  ]
}

what would you consider the best way to dealing with this situation? I hope there’s a magic bullet that won’t be a pita, so any tips will be greatly appreciated.

You would need to walk the array and check if the value of the key is valid JSON then decode it.

using array_walk
https://www.php.net/manual/en/function.array-walk.php

the solution probably exists somewhere in the land of google.