6

Here is a json file containing various attributes relating to countries. However, it does not contain any geographic data.

http://bost.ocks.org/mike/nations/nations.json

I would like to join these attributes with another file that has the geographic data for the countries. But I can't figure out how to get it into QGIS.

Is there a way of loading non-geojson json files into QGIS?

6

Yes, you can import non-geo JSON files into QGIS but there are no native method for this in QGIS. It's because in your link, it's non tabular data. For each "column" (like income) per country, you have year and value. You need to preprocess the data to change the structure to flatten it to 2 dimensions.

One choice could be to use PyQGIS console to solve this issue. In first, you get the data with standard Python urllib2 and json libraries and process it with Python. Then, using a memory provider, you can integrate the data as a layer and make your join. Be aware that if you need to reuse the data later, you will need to execute again the operations. So, you will need to save your memory layer or use the "Memory Layer Saver" plugin (but this plugin keeps data persistent per project).

Another choice could be to avoid QGIS completely at the beginning and generate a CSV from the data using Python (outside QGIS). Then, you can load the CSV file in QGIS.

For PyQGIS, look at the PYQGIS cookbook.

  • Thanks. Converting to csv is what I did actually. When I work with json files, I always find myself converting them to csv's or modifying them with a script before I can use them. Considering how common the json format is, I thought I might be missing something. – mgalka Oct 3 '15 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.