Hi Jonathan,
I believe I am indirectly assisting you with this issue but for the benefit of others this is how you would accomplish the result. You can do this two ways:
Using only the ArcGIS API for Python:
- It is recommended to use an in-memory python dictionary object.
- Since we're dealing with a Web Map you don't want to use data=jsonfile.json. Rather, you want to set the aforementioned in-memory dictionary as the value of the ‘text’ attribute in the 'item_properties' argument. This is explained here: arcgis.gis module — arcgis 1.5.1 documentation
text | Optional string. For text based items such as Feature Collections & WebMaps |
I used a simplified version of your original JSON so you'll just need to add/update the parts you need...
from arcgis.gis import GIS
from arcgis.mapping import WebMap
gis = GIS("PORTALURL","LOGIN","PASSWORD")
data = {"operationalLayers": [],"baseMap": {"baseMapLayers": [{"id": "labels","opacity": 1,"visibility": True,"url": "https://geoappext.nrcan.gc.ca/arcgis/rest/services/BaseMaps/CBMT_CBCT_GEOM_3857/MapServer"},{"id": "base","opacity": 1,"visibility": True,"url": "https://geoappext.nrcan.gc.ca/arcgis/rest/services/BaseMaps/CBMT_TXT_3857/MapServer"}],"title": "Text"}}
item_properties_dict = {"type": "Web Map","title": "Test Map","tags": ["test","basemap","pythonapi"],"snippet":"This is a snippet", "text":data}
newmap = gis.content.add(item_properties = item_properties_dict)
newmap
Reading from a JSON File:
from arcgis.gis import GIS
from arcgis.mapping import WebMap
import json
gis = GIS("PORTALURL","LOGIN","PASSWORD")
with open('/path/to/file/test2.json') as json_data:
data = json.load(json_data)
item_properties_dict = {"type": "Web Map","title": "Test Map","tags": ["test","basemap","pythonapi"],"snippet":"This is a snippet", "text":data}
newmap = gis.content.add(item_properties = item_properties_dict)
newmap
Where test2.json is a file with the below contents:
{
"operationalLayers": [],
"baseMap": {
"baseMapLayers": [{
"id": "labels",
"opacity": 1,
"visibility": true,
"url": "https://geoappext.nrcan.gc.ca/arcgis/rest/services/BaseMaps/CBMT_CBCT_GEOM_3857/MapServer"
}, {
"id": "base",
"opacity": 1,
"visibility": true,
"url": "https://geoappext.nrcan.gc.ca/arcgis/rest/services/BaseMaps/CBMT_TXT_3857/MapServer"
}
],
"title": "Text"
}
}
Here note that true is lowercase - in this case, you need to make this lowercase or else the json will fail to load. It needs to be capitalized, on the other hand, if you just use the API.