HOW TO

Save web maps and web applications as JSON files

Last Published: June 29, 2022

Summary

JavaScript Object Notation (JSON) is a standard text-based format that represents structured data based on the JavaScript object syntax. Web map and web application data can be saved as JSON files and stored on the machine to ease data transfer and recovery.

Use the workflows highlighted in this article to download the web maps and web applications as JSON files.

Procedure

Retrieve and save the JSON data for a specific web map or web application

  1. Import the necessary modules including the JSON module.
from arcgis import gis
from arcgis.gis import GIS
import json
  1. Specify the ArcGIS Online credentials to use.
gis = GIS("https://arcgis.com", "Username", "Password")
print("Connected.")
  1. Specify the web map ID in ArcGIS Online.
web_map = gis.content.get("<item ID>") #Edit the item ID
jsonData=web_map.get_data(try_json=True)
  1. Save the JSON details as a .json file in a folder location.
with open (r"<Folder Location>", "w") as file_handle: #Edit the folder location
    file_handle.write(json.dumps(jsonData))

print("Completed")

The following code block demonstrates the full script.

from arcgis import gis
from arcgis.gis import GIS
import json

gis = GIS("https://arcgis.com", "Username", "Password")
print("Connected.")

web_map = gis.content.get("0424sdgshhfjtRFSb9469ef")
jsonData=web_map.get_data(try_json=True)

with open (r"C:\Users\USER\Desktop\TEST\testingWebMap.json", "w") as file_handle:
    file_handle.write(json.dumps(jsonData))

print("Completed")

Retrieve and save all the JSON data listed under a specific owner in ArcGIS Online

  1. Import the necessary modules including the JSON module.
from arcgis import gis
from arcgis.gis import GIS
import json
  1. Specify the ArcGIS Online credentials to use.
gis = GIS("https://arcgis.com", "Username", "Password")
print("Connected.")
  1. Search all the web maps or web applications in the ArcGIS Online account of the owner.
x=0
my_item = gis.content.search(query="owner:<Owner Name>",item_type="Web Map") #Edit the owner's name and the item_type parameter
print(my_item)
  1. Iterate through the list of searched items to retrieve the JSON details and save them as .json files in a folder location.
for item in my_item:
    my_item = gis.content.search(query="owner:<Owner Name>",item_type="Web Map")[x] #Edit the owner's name and the item_type parameter
    item = my_item.get_data(try_json=True)
    with open (r"<Folder Location", "w") as file_handle: #Edit the folder location
        file_handle.write(json.dumps(item))
    x=x+1
    
print("Completed")

The following code block demonstrates the full script.

from arcgis import gis
from arcgis.gis import GIS
import json

gis = GIS("https://arcgis.com", "Username", "Password")
print("Connected.")

x=0
my_item = gis.content.search(query="owner:USER",item_type="Web Map")
print(my_item)

for item in my_item:
    my_item = gis.content.search(query="owner:USER",item_type="Web Map")[x]
    item = my_item.get_data(try_json=True)
    with open (r"C:\Users\USER\Desktop\TEST\testingWebMap.json", "w") as file_handle:
        file_handle.write(json.dumps(item))
    x=x+1
    
print("Completed")

Article ID:000027813

Software:
  • ArcGIS Online
  • ArcGIS API for Python 1 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic