<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Read, Parse, write to variable from JSON in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/read-parse-write-to-variable-from-json/m-p/1675419#M75035</link>
    <description>&lt;P&gt;When dealing with json data like this I like to take a second and mock it up using TypedDict:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from typing import Any, TypedDict

class FieldInfo(TypedDict):
    fieldName: str
    isEditable: bool
    label: str
    visible: bool

class PopupElement(TypedDict):
    type: str
    description: str
    fieldInfos: list[FieldInfo]

class PopupInfo(TypedDict):
    popupElements: list[PopupElement]
    title: str
    showAttachments: bool
    expressionInfos: list[Any]
    fieldInfos: list[FieldInfo]

class Layer(TypedDict):
    id: str
    title: str
    url: str
    itemId: str
    layerType: str
    popupInfo: PopupInfo

class GroupLayer(TypedDict):
    id: str
    title: str
    layers: list[Layer]
    layerType: str

class BaseMapLayer(TypedDict):
    id: str
    opacity: float
    title: str
    visibility: bool
    layerType: str
    styleUrl: str
    isReference: bool

class BaseMap(TypedDict):
    title: str
    baseMapLayers: list[BaseMapLayer]
    title: str

class SpatialReference(TypedDict):
    latestWkid: int
    wkid: int

class Extent(TypedDict):
    spatialReference: SpatialReference
    xmin: float
    xmax: float
    ymin: float
    ymax: float

class Viewpoint(TypedDict):
    targetGeometry: Extent

class State(TypedDict):
    viewpoint: Viewpoint

class Response(TypedDict):
    operationalLayers: list[Layer | GroupLayer]
    baseMap: BaseMap
    authoringApp: str
    authoringAppVersion: str
    initialState: State
    spatialReference: SpatialReference
    timeZone: str
    version: str&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now you can use your linter to determine keys for each part of the Response.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Dec 2025 03:41:15 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2025-12-31T03:41:15Z</dc:date>
    <item>
      <title>Read, Parse, write to variable from JSON</title>
      <link>https://community.esri.com/t5/python-questions/read-parse-write-to-variable-from-json/m-p/1674069#M75012</link>
      <description>&lt;P&gt;I have the below JSON output ... I need to read this JSON dictionary and write the 3 'url' values in BOLD to a variable...&amp;nbsp;&lt;/P&gt;&lt;P&gt;data = json.loads(wm_data)&lt;/P&gt;&lt;P&gt;varlayers = data['operationalLayers']['layers']['url']&lt;/P&gt;&lt;P&gt;Not sure how to and how to loop through the entire JSON to capture all 3... and it might be only 2 sometimes and maybe more... Any ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;{'operationalLayers': [{'id': '19397948adc-layer-1', 'title': 'Neighborhood Utility Permits uat', 'layers': [{'id': '19397948c74-layer-2', 'title': 'Neighborhood Permit Polygon'&lt;STRONG&gt;, 'url': '&lt;A href="https://services.arcgis.com/pxxxxxxxxxxl7/arcgis/rest/services/Neighborhood_Utility_Permits_uat/FeatureServer/2" target="_blank" rel="noopener"&gt;https://services.arcgis.com/pxxxxxxxxxxl7/arcgis/rest/services/Neighborhood_Utility_Permits_uat/FeatureServer/2&lt;/A&gt;',&lt;/STRONG&gt; 'itemId': '63721bd01f5a475291066c688c7feab8', 'layerType': 'ArcGISFeatureLayer', 'popupInfo': {'popupElements': [{'type': 'fields', 'description': '', 'fieldInfos': [{'fieldName': 'PERMIT_NUMBER', 'isEditable': True, 'label': 'Permit Number', 'visible': True}, {'fieldName': 'CUSTOMER_NAME', 'isEditable': True, 'label': 'Customer Name', 'visible': True}, {'fieldName': 'ANTICIPATEDSTART', 'isEditable': True, 'label': 'Anticipated Start Date', 'visible': True}, {'fieldName': 'ANTICIPATEDCOMPLETE', 'isEditable': True, 'label': 'Anticipated Completed Date', 'visible': True}], 'title': ''}, {'type': 'attachments', 'description': '', 'displayType': 'preview', 'title': ''}], 'showAttachments': True, 'expressionInfos': [], 'fieldInfos': [{'fieldName': 'OBJECTID', 'format': {'digitSeparator': False, 'places': 0}, 'isEditable': False, 'label': 'OBJECTID', 'visible': False}, {'fieldName': 'CUSTOMER_NAME', 'isEditable': True, 'label': 'Customer Name', 'visible': True}, {'fieldName': 'PERMIT_NUMBER', 'isEditable': True, 'label': 'Permit Number', 'visible': True}, {'fieldName': 'GLOBALID', 'isEditable': False, 'label': 'GLOBALID', 'visible': False}, {'fieldName': 'ANTICIPATEDSTART', 'isEditable': True, 'label': 'Anticipated Start Date', 'visible': True}, {'fieldName': 'ANTICIPATEDCOMPLETE', 'isEditable': True, 'label': 'Anticipated Completed Date', 'visible': True}], 'title': 'Neighborhood Utility Permit Polygon'}}, {'id': '19397948c75-layer-3', 'title': 'Neighborhood Permit Line', &lt;STRONG&gt;'url': '&lt;A href="https://services.arcgis.com/pxxxxxxxxxxxx/arcgis/rest/services/Neighborhood_Utility_Permits_uat/FeatureServer/1" target="_blank" rel="noopener"&gt;https://services.arcgis.com/pxxxxxxxxxxxx/arcgis/rest/services/Neighborhood_Utility_Permits_uat/FeatureServer/1&lt;/A&gt;',&lt;/STRONG&gt; 'itemId': '63721bd01f5a475291066c688c7feab8', 'layerType': 'ArcGISFeatureLayer', 'popupInfo': {'popupElements': [{'type': 'fields', 'description': '', 'fieldInfos': [{'fieldName': 'PERMIT_NUMBER', 'isEditable': True, 'label': 'Permit Number', 'visible': True}, {'fieldName': 'CUSTOMER_NAME', 'isEditable': True, 'label': 'Customer Name', 'visible': True}, {'fieldName': 'ANTICIPATEDSTART', 'isEditable': True, 'label': 'Anticipated Start Date', 'visible': True}, {'fieldName': 'ANTICIPATEDCOMPLETE', 'isEditable': True, 'label': 'Anticipated Completed Date', 'visible': True}], 'title': ''}, {'type': 'attachments', 'description': '', 'displayType': 'preview', 'title': ''}], 'showAttachments': True, 'expressionInfos': [], 'fieldInfos': [{'fieldName': 'OBJECTID', 'format': {'digitSeparator': False, 'places': 0}, 'isEditable': False, 'label': 'OBJECTID', 'visible': False}, {'fieldName': 'CUSTOMER_NAME', 'isEditable': True, 'label': 'Customer Name', 'visible': True}, {'fieldName': 'GLOBALID', 'isEditable': False, 'label': 'GLOBALID', 'visible': False}, {'fieldName': 'PERMIT_NUMBER', 'isEditable': True, 'label': 'Permit Number', 'visible': True}, {'fieldName': 'ANTICIPATEDSTART', 'isEditable': True, 'label': 'Anticipated Start Date', 'visible': True}, {'fieldName': 'ANTICIPATEDCOMPLETE', 'isEditable': True, 'label': 'Anticipated Completed Date', 'visible': True}], 'title': 'Neighborhood Utility Permit Line'}}, {'id': '19397948c75-layer-4', 'title': 'Neighborhood Permit Point', &lt;STRONG&gt;'url': '&lt;A href="https://services.arcgis.com/p5xxxxxxxxxx7/arcgis/rest/services/Neighborhood_Utility_Permits_uat/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/p5xxxxxxxxxx7/arcgis/rest/services/Neighborhood_Utility_Permits_uat/FeatureServer/0&lt;/A&gt;',&lt;/STRONG&gt; 'itemId': '63721bd01f5a475291066c688c7feab8', 'layerType': 'ArcGISFeatureLayer', 'popupInfo': {'popupElements': [{'type': 'fields', 'description': '', 'fieldInfos': [{'fieldName': 'PERMIT_NUMBER', 'isEditable': True, 'label': 'Permit Number', 'visible': True}, {'fieldName': 'CUSTOMER_NAME', 'isEditable': True, 'label': 'Customer Name', 'visible': True}, {'fieldName': 'ANTICIPATEDSTART', 'isEditable': True, 'label': 'Anticipated Start Date', 'visible': True}, {'fieldName': 'ANTICIPATEDCOMPLETE', 'isEditable': True, 'label': 'Anticipated Completed Date', 'visible': True}], 'title': ''}, {'type': 'attachments', 'description': '', 'displayType': 'preview', 'title': ''}], 'showAttachments': True, 'expressionInfos': [], 'fieldInfos': [{'fieldName': 'OBJECTID', 'format': {'digitSeparator': False, 'places': 0}, 'isEditable': False, 'label': 'OBJECTID', 'visible': False}, {'fieldName': 'CUSTOMER_NAME', 'isEditable': True, 'label': 'Customer Name', 'visible': True}, {'fieldName': 'PERMIT_NUMBER', 'isEditable': True, 'label': 'Permit Number', 'visible': True}, {'fieldName': 'GLOBALID', 'isEditable': False, 'label': 'GLOBALID', 'visible': False}, {'fieldName': 'ANTICIPATEDSTART', 'isEditable': True, 'label': 'Anticipated Start Date', 'visible': True}, {'fieldName': 'ANTICIPATEDCOMPLETE', 'isEditable': True, 'label': 'Anticipated Completed Date', 'visible': True}], 'title': 'Neighborhood Utility Permit Point'}}], 'layerType': 'GroupLayer'}], 'baseMap': {'baseMapLayers': [{'id': 'VectorTile_3714', 'opacity': 1, 'title': 'Human Geography Base', 'visibility': True, 'layerType': 'VectorTileLayer', 'styleUrl': '&lt;A href="https://cdn.arcgis.com/sharing/rest/content/items/2afe5b807fa74006be6363fd243ffb30/resources/styles/root.json" target="_blank" rel="noopener"&gt;https://cdn.arcgis.com/sharing/rest/content/items/xyzxyzxyz/resources/styles/root.json&lt;/A&gt;'}, {'id': 'VectorTile_9220', 'opacity': 0.38, 'title': 'Human Geography Detail', 'visibility': True, 'layerType': 'VectorTileLayer', 'styleUrl': '&lt;A href="https://cdn.arcgis.com/sharing/rest/content/items/97fa1365da1e43eabb90d0364326bc2d/resources/styles/root.json" target="_blank" rel="noopener"&gt;https://cdn.arcgis.com/sharing/rest/content/items/xyzxyzxyzxy/resources/styles/root.json&lt;/A&gt;', 'isReference': True}, {'id': 'VectorTile_1103', 'opacity': 1, 'title': 'Human Geography Label', 'visibility': True, 'layerType': 'VectorTileLayer', 'styleUrl': '&lt;A href="https://cdn.arcgis.com/sharing/rest/content/items/018d570994c34c1884f078fe056f5d4a/resources/styles/root.json" target="_blank" rel="noopener"&gt;https://cdn.arcgis.com/sharing/rest/content/items/xyzxyzxyzxy/resources/styles/root.json&lt;/A&gt;', 'isReference': True}], 'title': 'Human Geography Map'}, 'authoringApp': 'ArcGISMapViewer', 'authoringAppVersion': '2024.2', 'initialState': {'viewpoint': {'targetGeometry': {'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'xmin': -9361030.36503893, 'ymin': 4281372.106805783, 'xmax': -8353896.080353716, 'ymax': 4839056.665174281}}}, 'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'timeZone': 'system', 'version': '2.32'}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 20:19:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-parse-write-to-variable-from-json/m-p/1674069#M75012</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2025-12-18T20:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Read, Parse, write to variable from JSON</title>
      <link>https://community.esri.com/t5/python-questions/read-parse-write-to-variable-from-json/m-p/1674088#M75013</link>
      <description>&lt;P&gt;The reason your current code is failing is that operationalLayers is a list (indicated by the [ bracket), and inside that list, your layers are nested inside a Group Layer.&lt;/P&gt;&lt;P&gt;To get all those URLs regardless of how many there are, you need to loop through the operational layers and then loop through the sub-layers inside them.&lt;/P&gt;&lt;P&gt;Here is a simple way to do it using a list comprehension:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Create a list to store all URLs found
urls = []

# Loop through the operational layers
for op_layer in data.get('operationalLayers', []):
    # Check if this is a group layer containing a sub-list of layers
    if 'layers' in op_layer:
        for sub_layer in op_layer['layers']:
            if 'url' in sub_layer:
                urls.append(sub_layer['url'])
    # Also check the top-level op_layer in case it's not a group
    elif 'url' in op_layer:
        urls.append(op_layer['url'])

print(urls)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 18 Dec 2025 20:54:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-parse-write-to-variable-from-json/m-p/1674088#M75013</guid>
      <dc:creator>VenkataKondepati</dc:creator>
      <dc:date>2025-12-18T20:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: Read, Parse, write to variable from JSON</title>
      <link>https://community.esri.com/t5/python-questions/read-parse-write-to-variable-from-json/m-p/1675419#M75035</link>
      <description>&lt;P&gt;When dealing with json data like this I like to take a second and mock it up using TypedDict:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from typing import Any, TypedDict

class FieldInfo(TypedDict):
    fieldName: str
    isEditable: bool
    label: str
    visible: bool

class PopupElement(TypedDict):
    type: str
    description: str
    fieldInfos: list[FieldInfo]

class PopupInfo(TypedDict):
    popupElements: list[PopupElement]
    title: str
    showAttachments: bool
    expressionInfos: list[Any]
    fieldInfos: list[FieldInfo]

class Layer(TypedDict):
    id: str
    title: str
    url: str
    itemId: str
    layerType: str
    popupInfo: PopupInfo

class GroupLayer(TypedDict):
    id: str
    title: str
    layers: list[Layer]
    layerType: str

class BaseMapLayer(TypedDict):
    id: str
    opacity: float
    title: str
    visibility: bool
    layerType: str
    styleUrl: str
    isReference: bool

class BaseMap(TypedDict):
    title: str
    baseMapLayers: list[BaseMapLayer]
    title: str

class SpatialReference(TypedDict):
    latestWkid: int
    wkid: int

class Extent(TypedDict):
    spatialReference: SpatialReference
    xmin: float
    xmax: float
    ymin: float
    ymax: float

class Viewpoint(TypedDict):
    targetGeometry: Extent

class State(TypedDict):
    viewpoint: Viewpoint

class Response(TypedDict):
    operationalLayers: list[Layer | GroupLayer]
    baseMap: BaseMap
    authoringApp: str
    authoringAppVersion: str
    initialState: State
    spatialReference: SpatialReference
    timeZone: str
    version: str&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now you can use your linter to determine keys for each part of the Response.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2025 03:41:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-parse-write-to-variable-from-json/m-p/1675419#M75035</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-12-31T03:41:15Z</dc:date>
    </item>
  </channel>
</rss>

