Using JSON Data types in PostgreSQL
While arrays can be useful for storing a list of values in a single field, sometimes your data structures can be complex. You might want to store multiple values of different types in a single field, and you might want data to be keyed with labels rather than stored sequentially. These are common issues with log-level data, as well as alternative data. For example, a healthcare patient database may contain a field called prescription, which contains all the prescriptions of a patient. Some patients may not have any prescriptions, thus this field may be empty. Other patients may have multiple prescriptions, and each patient's prescription may be different from the others. One patient may have a hypertension drug of 10mg per day. Another may have an insomnia drug of two pills per night. Yet another patient may have both. It is very hard to store these in a predefined format, so they are usually stored as key-value pairs using the JSON format.
...