Save list of WebMaps as json file using ArcGIS API python

393
3
Jump to solution
04-13-2022 02:32 AM
Aravinthkumar
New Contributor III

Hello Everyone, 

I have list of WebMap with its Item id's, Is is possible to save the items information as JSON file for backup and can be used later to update the WebMap. How can I save the list of WebMap items information as JSON using ArcGIS API python ?? 

Thank you. 

Tags (1)
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

When you get a web map's properties, you can simply use the json module to conver the properties dict to JSON, then write that to a file.

Can you elaborate on what your list looks like? Is it just a list of itemIDs?

Assuming you have a list of ids as strings, you could do something like this:

from arcgis import GIS

gis = GIS('your portal url')
maps = ['list', 'of', 'itemids']
out_dir = 'output directory'

for m in maps:
    prop = gis.content.get(m).get_data()
    
    with open(f'{out_dir}/{m}.json', 'w') as file:
        file.write(json.dumps(prop))

 

Which results in something like the following (ignore that 'test.gdb' item):

jcarlson_0-1649857431893.png

Any of which, if you opened up, would have the full JSON of the web map.

jcarlson_1-1649857479014.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

3 Replies
jcarlson
MVP Esteemed Contributor

When you get a web map's properties, you can simply use the json module to conver the properties dict to JSON, then write that to a file.

Can you elaborate on what your list looks like? Is it just a list of itemIDs?

Assuming you have a list of ids as strings, you could do something like this:

from arcgis import GIS

gis = GIS('your portal url')
maps = ['list', 'of', 'itemids']
out_dir = 'output directory'

for m in maps:
    prop = gis.content.get(m).get_data()
    
    with open(f'{out_dir}/{m}.json', 'w') as file:
        file.write(json.dumps(prop))

 

Which results in something like the following (ignore that 'test.gdb' item):

jcarlson_0-1649857431893.png

Any of which, if you opened up, would have the full JSON of the web map.

jcarlson_1-1649857479014.png

 

- Josh Carlson
Kendall County GIS
Aravinthkumar
New Contributor III

Hello Josh Carlson, 

Thank you for the input. The list looks like below with 56 map id's in a file 

fds.PNG

Does this kind of input can be used ?? 

What should be given in the below variable maps ? 

maps = ['list', 'of', 'itemids']

Does this also saves the legends of the Maps ?? 

 

Thank you. 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Yes, it can certainly be used. You should refer to python's read method for more information about how to do that.

A map's legend is based on layer symbology, which is defined in the JSON, so yes, the legend will be the same.

- Josh Carlson
Kendall County GIS