HOW TO

Retrieve the JSON of a specific layer in a feature service using ArcGIS API for Python

Last Published: May 30, 2023

Summary

The JSON of a feature service layer contains information such as the layer's geometry type, min and max scales, and spatial reference. The Python script provided in this article can be used to access the JSON of a feature service layer.

Procedure

  1. Import the necessary modules.
import arcgis
  1. Specify the credentials to connect to the portal.
gis = arcgis.gis.GIS("<portal_URL>", "<username>", "<password>", verify_cert=False)
  1. Specify the item ID and layer ID of the service to be queried.
item = gis.content.get("<portal_itemID>")
resturl = dict(item)["url"]
layerurl = str(resturl) + "/" + str(<item_layerID>)
layer = arcgis.features.FeatureLayer(layerurl)
  1. Print the JSON properties.
print(layerurl+"?f=pjson")
print(layer.properties)

The code block below demonstrates the full script.

import arcgis

gis = arcgis.gis.GIS("https://machines.esri.com/portal", "username1", "password1", verify_cert=False)

item = gis.content.get("asd651cqe84c6d51a")
resturl = dict(item)["url"]
layerurl = str(resturl) + "/" + str(0)
layer = arcgis.features.FeatureLayer(layerurl)

print(layerurl+"?f=pjson")
print(layer.properties)

The JSON of the specific feature service layer is returned after running the script.

The JSON displaying the information of the specific feature service layer in ArcGIS Notebooks.

Article ID: 000030408

Software:
  • Portal for ArcGIS
  • ArcGIS Server
  • ArcGIS API for Python
  • ArcGIS Enterprise 10 x
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options