<div dir="ltr"><div>Hi,</div><div><br></div><div>that doesn't look valid GeoJSON to me, you have no other options than transforming the JSON to valid GeoJSON (or to any other format recognized by QGIS ogr provider), or you can create a vector layer from scratches and and add the individual features in a loop, it largely depends on what you need to do next with those data.<br></div><div><br></div><div>Both approaches require a bit of programming.</div><div></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 25, 2019 at 6:10 PM Cliff Patterson <<a href="mailto:cpatterson@psdrcs.com">cpatterson@psdrcs.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I have a JSON endpoint that I want to load into a QGIS project as a flat table (no geometry). There are lat/ling coordinates in JSON (see below), but those coords are not important for my purpose since I want to eventually join the table with a spatial layer using a common ID. I can load the data into the console with:</div><div><br></div><div>import urllib.request, json, csv<br>with urllib.request.urlopen("<a href="https://my_json_endpoint" target="_blank">https://my_json_endpoint</a>") as url:<br> data = json.loads(url.read().decode())<br> print(data)<br></div><div><br></div><div>And I can load the table into QGIS as a GeoJSON with: </div><div><br></div><div>import urllib.request, json<br>uri = '<a href="https://my_json_endpoint" target="_blank">https://my_json_endpoint</a>'<br>iface.addVectorLayer(uri, 'Asset Data', 'ogr')<br></div><div><br></div>but the table loads without attribute data and no rows. <div><br></div><div>The JSON file looks like this (but with 20+ rows of data)</div><div><br></div><div><pre style="color:rgb(0,0,0);white-space:pre-wrap">{
"Assets": [
{
"adjusted_cost": 1940993,
"adjusted_eul": 240,
"adjusted_quantity": 1,
"amort_date": "2039-11-01",
"attributes": [],
"classifications": {
"Acc. Amort. Code": "No Acc. Amort. Code",
"Amort. Exp. Code": "No Amort. Exp. Code",
"Capital Code": "No Capital Code",
"Category": "Roads",
"Class": "Infrastructure",
"Department": "No Department",
"Function": "No Function",
"Schedule 51B Code": "No Schedule 51B Code",
"Schedule 75C Code": "No Schedule 75C Code",
"Segment": "Surface",
"Sub-Function": "No Sub-Function"
},
"condition": 100,
"condition_assessment_date": "Age-based",
"condition_ratio": 1,
"description": null,
"eul": 240,
"gis_feature_id": "roads.1",
"historical_cost": 1940993,
"id": 1,
"import_id": "PATCH-1",
"initial_quantity": 1,
"is_fully_disposed": false,
"is_fully_transferred": false,
"is_lifecycle_excluded": true,
"lat": 42.985708676898,
"lifecycle_eul": 240,
"lifecycle_eul_events": 240,
"location": null,
"lon": -81.254337208244,
"name": "Road name 1",
"profile": "Default Profile",
"replacement_cost": 0,
"replacement_date": "2039-11-01",
"risk_consequence": 5,
"risk_probability": 1,
"risk_rating": 5,
"service_date": "2019-11-12",
"unit_of_measure": "Area (m2)"
},</pre><pre style="color:rgb(0,0,0);white-space:pre-wrap"> ...</pre><pre style="color:rgb(0,0,0);white-space:pre-wrap">}</pre><pre style="color:rgb(0,0,0);white-space:pre-wrap"><br></pre><pre style="color:rgb(0,0,0);white-space:pre-wrap">I could write a script to load the data into a DB table dynamically, but it would be much better to load the data dynamically in QGIS. The ultimate objective would be to create a tool that loads the data for the user. </pre><pre style="color:rgb(0,0,0);white-space:pre-wrap">Any ideas how I can achieve this? </pre><pre style="color:rgb(0,0,0);white-space:pre-wrap">Thanks!</pre><pre style="color:rgb(0,0,0);white-space:pre-wrap">Cliff</pre></div></div>
_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a></blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">Alessandro Pasotti<br>w3: <a href="http://www.itopen.it" target="_blank">www.itopen.it</a></div>