Select to view content in your preferred language

Save items as json with ArcGIS API for Pyhton

5399
4
Jump to solution
04-19-2017 07:11 AM
GISMountains
Occasional Contributor

Hello 

Is there a way to save the items-information as JSON like the JSON we could see with ArcGIS Online Assistant

Espacially I would like to store the "Web Map"-json to backup this information.

Cheers

1 Solution

Accepted Solutions
by Anonymous User
Not applicable

You certainly can, checkout the `get_data()` method available on an `Item` object. You can make the `try_json` argument to False so you always download the JSON data.

The ArcGIS Online Assistant shows you both the item properties as JSON as well as the data resource as JSON. The `get_data()` gives you the latter. To get the item's properties as JSON, cast the Item object as a dictionary like below and write that to a file:

import json
my_item = gis.content.search("","Web Map")[0]
dict_my_item = dict(my_item)

with open ("path_to_webmap_json_file.json", "w") as file_handle:
    file_handle.write(json.dumps(dict_my_item))

View solution in original post

4 Replies
by Anonymous User
Not applicable

You certainly can, checkout the `get_data()` method available on an `Item` object. You can make the `try_json` argument to False so you always download the JSON data.

The ArcGIS Online Assistant shows you both the item properties as JSON as well as the data resource as JSON. The `get_data()` gives you the latter. To get the item's properties as JSON, cast the Item object as a dictionary like below and write that to a file:

import json
my_item = gis.content.search("","Web Map")[0]
dict_my_item = dict(my_item)

with open ("path_to_webmap_json_file.json", "w") as file_handle:
    file_handle.write(json.dumps(dict_my_item))
SolanaFoo2
Regular Contributor

Worked for me thank you!!

0 Kudos
DavidRunneals2
Regular Contributor

Once you get the json config data files for webmaps/webapps exported/backed up, is there a way to reimport them? I was looking at the additem or addpart API calls. What is the best way to do that?

Also, I know that I'll have to deal with updating the item IDs of web maps in the app configs (any ideas on best practices to do that)?

Can't wait until the ArcGIS online team can support backup/restore of entire orgs

simoxu
by MVP Regular Contributor
MVP Regular Contributor

Not sure what you mean by saying 'reimport'... 

if you mean creating an item using the JSON you've got, yes you can. here is an example:

How To: Create a web map from a JSON file using ArcGIS API for Python

0 Kudos