Skip to content
Advertisement

How to append nested key-value to json array in postgresql?

My json values in jsonb column are below:

I have nested key – "Images" that has array of strings. How to write query that will add to Images new keys/values ("UploadedBy":null and "Size":null) and transform array of string to key-value ("https://face.png" -> "Link":"https://face.png") like below:

Advertisement

Answer

You can use jsonb_set:

See fiddle.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement