I want to use arcpy to download a JSON file form "NoiseTube.net" and convert the file to a feature class. However, i'm finding it difficult to complete this task, since the json file does not contain "geometry" and "type" keys. I want to be assisted to complete my task. Attached, is my script

import arcpy
import os
from urllib import request
import json
import tempfile

url = "http://www.noisetube.net/users/11463/tracks/88383.json"
temp_dir = tempfile.mkdtemp()
filename = os.path.join(temp_dir, "Noise.json")
response = request.urlretrieve(url, filename)
json_file = open(filename)
json_raw = json.load(json_file)

arcpy.management.CreateFileGDB(r"Z:\ARCGIS", "Noisetube.gdb")
arcpy.env.workspace = r"Z:\ARCGIS\Noisetube.gdb"

Example of the JSON:

  • If this JSON has no spatial information in it then there does not appear to be a GIS component to your question. If it does, then please describe what it is.
    – PolyGeo
    Jul 3 '20 at 18:47
  • This JSON has a lat/long. But it’s not geojson or esrijson, this it’ll need to be manually parsed. There is no out of the box parser that will handle this.
    – KHibma
    Jul 3 '20 at 19:36

Here is a script that reads in the json file and outputs a csv that can be imported into ArcMap. This is something that you will need to do frequently when dealing with json data as many sources won't be in geojson or esrijson.

import json
import csv

#read in json data
with open("data.json","r") as f:
    data = json.load(f)

#open output file
with open("noisedata.csv","w",newline="") as f:
    wtr = csv.writer(f,quoting=csv.QUOTE_NONNUMERIC)
    #build csv header row
    headers = data['dataset'][0].keys()

    #iterate through items in json file
    for curr_item in data['dataset']:

        #check that all data elements are valid
        if curr_item['lat'] and curr_item['lng'] and curr_item['db'] and curr_item['date'] and curr_item['id']:
            #convert inputs
            curr_row = [float(curr_item['lat']),float(curr_item['lng']),float(curr_item['db']),
            #write current row to output file

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.