I tried to retrieve the data from JSON file and assign them into object type like code the below. The data has multiple arrays in order with lat and lng. Using Python how could I deal with this one?
Current Python code*
import os
from flask import Flask, render_template, abort, url_for, json
import json
app = Flask(__name__)
...
with open('./data/file.json', 'r') as myfile:
data = myfile.read()
features = json.loads(data)['features']
for o in features:
print(o['coordinates'])). <----'Data from JSON file'
...
app.run(host='localhost', debug=True)
Orginal JSON file
{
"features": [{
"coordinates": [
[
[
-79.3998992207101,
43.770625433748776
],
[
-79.39977945240246,
43.770651091617324
],
[
-79.39970177723474,
43.77046066096583
],
[
-79.39982154480901,
43.77043500133246
],
[
-79.3998992207101,
43.770625433748776
]
]
]
}]
}
Data from JSON file
[[[-79.3998992207101, 43.770625433748776], [-79.39977945240246, 43.770651091617324], [-79.39970177723474, 43.77046066096583], [-79.39982154480901, 43.77043500133246], [-79.3998992207101, 43.770625433748776]]]
Result I am aiming at
var triangleCoords = [
{lat: -79.3998992207101, lng: 43.770625433748776},
{lat: -79.39977945240246, lng: 43.770651091617324},
{lat: -79.39970177723474, lng: 43.77042949785241},
{lat: -79.39987169202237, lng: 43.77039053223808}
.....
];
featuresimmediate, but there's nothing like that in your file.