In a postgres table I have some jsonb in this format
[{"type": "pet", "animal": "cat"}, {"type": "farm", "animal": "cow","colour": "brown"}]
But I want to turn it into this format
{"cat": {"type": "pet", "animal": "cat"}, "cow" {"type": "farm", "animal": "cow", "colour": "brown"}
And I can't figure it out or find anyone on the internet who has jsonb in this format. Can anyone solve this? Ideally the sets of data that don't have a key/value for "colour" won't have {"colour": null} but just won't have the key "colour" at all
I'm on postgres 9.6