ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Features To JSON

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

Converts features to JSON format. The fields, geometry, and spatial reference of features will be converted to their corresponding JSON representation and written to a file with a .json extension.

Usage

  • If you want the JSON representation in the output file to be more readable, you can enable formatting. The JSON will be formatted with spaces, tabs, and carriage returns to improve its readability. A formatted JSON may be beneficial for application development and testing. However, it is not recommended for actual production applications since all of the whitespace is unnecessary and ignored by JSON parsers. Additionally, formatted JSON can be significantly larger than its JSON equivalent, and the file size will be greater than its corresponding JSON representation. This can affect application performance.

  • The conversion does not support joins, relates, and attachments of the features.
  • To convert a subset of features in a feature class or layer, use the Select Layer By Attribute or Select Layer By Location tool and select the subset of features to be converted before using Features To JSON.

  • Check the Output to GeoJSON parameter (geoJSON='GEOJSON' in Python) to create JSON output that conforms to the GeoJSON specification. Esri JSON output is the default.

Syntax

arcpy.conversion.FeaturesToJSON(in_features, out_json_file, {format_json}, {include_z_values}, {include_m_values}, {geoJSON})
ParameterExplanationData Type
in_features

The features to convert to JSON.

Feature Layer
out_json_file

The output JSON file.

File
format_json
(Optional)

The JSON can be formatted to improve readability similar to the ArcGIS REST API specification's PJSON (Pretty JSON) format.

  • NOT_FORMATTED — The features will not be formatted. This is the default.
  • FORMATTED —The features will be formatted to improve readability.
Boolean
include_z_values
(Optional)

Include z-values of the features to the JSON.

  • NO_Z_VALUES — The z-values will not be included in geometries and the hasZ property of the JSON will not be included. This is the default.
  • Z_VALUES —The z-values will be included in geometries and the hasZ property of the JSON will be set to True.
Boolean
include_m_values
(Optional)

Include m-values of the features to the JSON.

  • NO_M_VALUES — The m-values will not be included in geometries and the hasM property of the JSON will not be included. This is the default.
  • M_VALUES —The m-values will be included in geometries and the hasM property of the JSON will be set to True.
Boolean
geoJSON
(Optional)

Create output as GeoJSON, conforming to the GeoJSON specification.

  • GEOJSON — The output will be created as GeoJSON.
  • NO_GEOJSON —The output will be created as Esri JSON. This is the default.
Boolean

Code sample

FeaturesToJSON example 1 (Python window)

The following Python window script demonstrates how to use the FeaturesToJSON function to create JSON and PJSON files.

import arcpy
import os
arcpy.env.workspace = "c:/data"
arcpy.FeaturesToJSON_conversion(os.path.join("outgdb.gdb", "myfeatures"), "myjsonfeatures.json")
arcpy.FeaturesToJSON_conversion(os.path.join("outgdb.gdb", "myfeatures"), "mypjsonfeatures.json", "FORMATTED")
FeaturesToJSON example 2 (Python window)

The following Python window script demonstrates how to use the FeaturesToJSON function with z- and m-values.

import arcpy
import os
arcpy.env.workspace = "c:/data"
arcpy.FeaturesToJSON_conversion(os.path.join("outgdb.gdb", "myfeatures"), "myjsonfeatures.json", "NOT_FORMATTED",
																																"Z_VALUES", "M_VALUES")
FeaturesToJSON example 3 (stand-alone script)

Convert a subset of features to JSON using SelectLayerByAttribute and SelectLayerByLocation.

# Import system modules
import arcpy

# Set the workspace
arcpy.env.workspace = "c:/data/mexico.gdb"

# Make a layer from the feature class
arcpy.MakeFeatureLayer_management("cities", "lyr") 
 
# Select all cities which overlap the chihuahua polygon
arcpy.SelectLayerByLocation_management("lyr", "intersect", "chihuahua", 0, "new_selection")

# Within selected features, further select only those cities which have a population > 10,000   
arcpy.SelectLayerByAttribute_management("lyr", "SUBSET_SELECTION", '"population" > 10000')
 
# Convert the selected features to JSON
arcpy.FeaturesToJSON_conversion("lyr", r"c:\data\myjsonfeatures.json")

Environments

  • Current Workspace
  • Scratch Workspace

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics

  • An overview of the JSON toolset
  • JSON To Features

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal