Код: Выделить всё
{
"layerId": "xxxx",
"url": "https://xxxx.com/server/rest/services/General/Boundaries/MapServer/2",
"name": "Grid",
"placeholder": "",
"searchFields": [
"GRID"
],
"displayField": "GRID",
"exactMatch": false,
"searchInCurrentMapExtent": false,
"panToScale": false,
"zoomScale": null,
"maxSuggestions": 6,
"maxResults": 6,
"type": "query"
}
Код: Выделить всё
def update_json(data, url_target, item_type, source_id=None, target_id=None):
def recursive_update(data):
if isinstance(data, dict):
return {k: recursive_update(v) for k, v in data.items()}
elif isinstance(data, list):
return [recursive_update(x) for x in data]
elif isinstance(data, str):
temp = data.replace('xxxx.com', url_target)
if item_type == 'app':
temp = temp.replace(source_id, target_id)
return temp
elif data is None:
return None
else:
return data
return recursive_update(data)
Подробнее здесь: https://stackoverflow.com/questions/793 ... ue-is-none