I am trying to import few data from a JSON file. The JSON file is nested and I want to import the child values. The JSO structure is something like this
{
"type": "FeatureCollection",
"properties": {
"zoom": 14,
"x": 12302,
"y": 7075
},
"features": [
{
"type": "FeatureCollection",
"properties": {
"layer": "poi",
"version": 3,
"extent": 4096
},
"features": [
{
"type": "Feature",
"id": 4356,
"properties": {
"fid": "eg-34678h765",
"name": "Brooklyn Children's Museum"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.944030,
40.674427
]
}
}
]
}
]
}
I want to fetch the following child values (given as like I call this with JS)
features[0].features[i].id
features[0].features[i].properties.fid
features[0].features[i].properties.name
features[0].features[i].geometry.coordinates[0]
features[0].features[i].geometry.coordinates[1]
into myTable entitled columns id, fid, name, longitude, latitude
I came up with a solution but that only insert the parent values like type, properties, features like this through psql
copy temp_json from 'E:\myJson.json';
insert into myTable ("type", "properties", "features")
select values->>'type' as type,
values->>'properties' as properties,
values->>'features' as features
from (
select json_array_elements(replace(values,'\','\\')::json) as values
from temp_json
) a;
where features inserted as JSONB.
How can I get my desired fields from the JSON file and insert into the targetted column of my table?