Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Estev's avatar
Level 2

Automatically decode json from query builder results

Hi,

I'm using the query builder to get data from an external database. I get a lot of nest json data (some fields are mysql json), i would like to find a way to automatically decode the json fields into arrays so i can work on them properly.

Output example from query builder :

{ id: 1, production_companies: "[{"id":9993,"logo_path":"\/2Tc1P3Ac8M479naPp1kYT3izLS5.png","name":"DC Entertainment","origin_country":"US"},{"id":174,"logo_path":"\/ky0xOc5OrhzkZ1N6KyUxacfQsCk.png","name":"Warner Bros. Pictures","origin_country":"US"},{"id":429,"logo_path":"\/2Tc1P3Ac8M479naPp1kYT3izLS5.png","name":"DC Comics","origin_country":"US"},{"id":83036,"logo_path":null,"name":"Joint Effort","origin_country":"US"},{"id":79,"logo_path":"\/tpFpsqbleCzEE2p5EgvUq6ozfCA.png","name":"Village Roadshow Pictures","origin_country":"US"},{"id":13240,"logo_path":"\/aTc07YaNHo8WNgkQSnvLmG6w4nW.png","name":"Bron Studios","origin_country":"CA"}]", }

for now i'm using json_decode on each field but sometime the fields are nested and the results are not consistents.

Any hint ?

Thank you.

0 likes
1 reply

Please or to participate in this conversation.