-4

I have this code inserted into the database: {"2":{"qty":1,"price":"10.00","room_id":{"1002":"1"}},"1":{"qty":2,"price":"35.00","room_id":["2"]},"3":{"qty":1,"price":"18.00","room_id":["1"]}}

I want to get the values FROM {"2":{"qty":1,"price":"10.00","room_id":{"1002":"1"}} TO "3":{"qty":1,"price":"18.00","room_id":["1"]}} and store each digit in a separate variable.

What would be the regular expression to match this?

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
Chris Zammit
  • 43
  • 1
  • 4

2 Answers2

11

what's the sytax i should use as regex please?

The answer is "none". You should not try to parse JSON using regexes. Use the json_decode() function instead.

0

If you need to store json data in the database, why don't you use some noSQL one that does json internally?

I'd go for MongoDB. Or possibly any of these: Databases using JSON as storage/transport format

Community
  • 1
  • 1
Peter Butkovic
  • 11,143
  • 10
  • 57
  • 81