I am a developer and have a tool that generates a geojson asset for our data team to work with using the QGIS app. Due to the original source of the data, these features have some attributes that are represented as complex hierarchical data, impossible to project into a flat schema.
We need to be able to view / edit the attribute field as effectively a JSON blob, instead of a string literal.
What facilities are available to do this in QGIS? Are there any field editing plugins that would support such a job? Ideally some kind of popup JSON editor with document format validation and collapsible nodes, similar to how Visual Studio (Code) editors work.
Alternatively some other workflow that would enable us to manage this data in an external tool and re-inject it into the source feature.
UPDATE: Got Postgres spun up and created a JSON column from an existing text column containing JSON. QGIS hides it in the attribute table. Any further recommendations on working with JSON attributes directly in the DB?
Best Answer
In recent QGIS versions (> 3.3), if you have a JSON field in a PostgreSQL database, you can use the
map_get
function anywhere with the Expression Dialog to extract a specific value.E.g if you have a JSON field called
"extraData"
and the contents are:then
map_get(extraData,'param1')
would produceSome string
I suppose (though I haven't tried it) you can recursively use the function to retrieve deeply nested values.
There are other functions such as the
from_json
function that returns the entire contents. Take a look at the Maps section inside the Expression Dialog.