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

murilo's avatar
Level 10

json mysql array

hello , I saw many examples of working with json field in Laravel + mysql . most of examples stores data in mysql like that -

features that has in house property ( example ) -

	{ "swimming_poll": 1, "garage": 1, "soccer field": 1 }

could I store the data like this as an Array in json my_sql field ?

["swimming_poll", "garage",  "soccer field"]

wold be a good approach ?

0 likes
4 replies
jlrdw's avatar

The bottom doesn't show how many. But the bottom is valid json. I'd suggest experiment with storing and outputs to determine what is needed.

Edit:

See here for an online json validator: https://jsonlint.com/

1 like
ctyler's avatar

@Tray2 I hope I am not hi jacking the thread but I am interested in best practice. I was just discussing json with @jlrdw and he linked to this thread. You give outstanding advice and I am curious what you think. I have gotten myself into trouble with json so I do not use it unless I think it necessary. In my opinion, I think this scenario is what a json field would be for. https://laracasts.com/discuss/channels/code-review/javascript-and-php This would be a field just for storing a dashboard layout for each user to keep track of widget placement.

Tray2's avatar
Tray2
Best Answer
Level 73

@ctyler I would still not use json for it, the main reason for that is that you have a set number of fields in your position. If it would have been a variable amount of fields then maybe I would have considered using a json column, or maybe a "key value" table. What I mean by that is that I would store each property and it's value in it's own record rather than in columns or json.

1 like

Please or to participate in this conversation.