VMware Tanzu Application Service for VMs

 View Only

 MySQL JSON Query

Siti Sarangi's profile image
Siti Sarangi posted Jan 16, 2019 09:40 PM

Hi I have a MYSQL Table with JSON Data Type. A sample value for JSON looks like this

{

"ID":"1234",

"Name":"Sample",

"Accounts":[

{

"Accid":"12345",

"Type":"Personal",

"Address":"test Address"},

{

"Accid":"42345",

"Type":"Personal",

"Address":"test Address"}

]

 

My Requirement is to fetch only the item from Accounts Array where Accid=12345.

 

Any idea how to write a query to get this done if its doable? I tried selecting Accounts with where Accid=12345 and it returns me the entire Accounts array.

Daniel Mikusa's profile image
Daniel Mikusa

I think this is what you want -> https://dev.mysql.com/doc/refman/5.7/en/json.html#json-paths

 

This is standard MySQL functionality though, nothing is specific to Pivotal software. For future issues not related to Pivotal software, you'll probably get more help on the MySQL forum or a place like Stack Overflow.