Features To JSON (Conversion)

Summary

Converts features to Esri JSON or GeoJSON 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 or .geojson extension.

Usage

  • You can enable formatting to make the JSON representation in the output file more readable. The output file will be formatted with spaces, tabs, and carriage returns to improve readability. A formatted JSON may be beneficial for application development and testing. However, it is not recommended for 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 larger 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.

  • Use the Output to GeoJSON parameter to create a .geojson file that conforms to the GeoJSON specification. The GeoJSON specification does not support curve geometry; input features that contain curves will be densified during conversion.

  • When the output is a .geojson file, you have the option to project the input features to the WGS 1984 coordinate system, which is the standard for the GeoJSON specification. A default geographic transformation will be applied if necessary. If this option is not used, the output .geojson file will contain a crs tag that can be used in some applications to define the coordinate system or coordinate reference system. This tag is not fully supported under the GeoJSON specification.

  • The tool's output will only include visible attribute fields from the input. To include all fields, you must make them all visible. Additionally, you can use the Use field aliases parameter to make the output use field aliases rather than field names.

Parameters

LabelExplanationData Type
Input Features

The features to convert to JSON format.

Feature Layer
Output JSON

The output .json or .geojson file.

File
Formatted JSON
(Optional)

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

  • Unchecked—The features will not be formatted. This is the default.
  • Checked—The features will be formatted to the PJSON specification.

Boolean
Include Z Values
(Optional)

Specifies whether the z-values of the features will be included in the JSON.

  • Unchecked—The z-values will not be included in geometries, and the hasZ property of the JSON will not be included. This is the default.
  • Checked—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)

Specifies whether the m-values of the features will be included in the JSON.

  • Unchecked—The m-values will not be included in geometries, and the hasM property of the JSON will not be included. This is the default.
  • Checked—The m-values will be included in geometries, and the hasM property of the JSON will be set to true.

Boolean
Output to GeoJSON
(Optional)

Specifies whether the output will be created in GeoJSON format.

  • Unchecked—The output will be created in Esri JSON format (.json file). This is the default.
  • Checked—The output will be created in GeoJSON format (.geojson file).

Boolean
Project to WGS_1984
(Optional)

Specifies whether the input features will be projected to the geographic coordinate system WGS_1984 with a default geographic transformation. This parameter only applies when the output is GeoJSON.

  • Checked—Features will be projected to WGS_1984.
  • Unchecked—Features will not be projected to WGS_1984. The GeoJSON will contain a CRS tag that defines the coordinate system. This is the default.

Boolean
Use field aliases
(Optional)

Specifies whether the output file will use field aliases for feature attributes.

  • Unchecked—Output feature attributes will not use field aliases; they will use field names. This is the default.
  • Checked—Output feature attributes will use field aliases.

Boolean

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

The features to convert to JSON format.

Feature Layer
out_json_file

The output .json or .geojson file.

File
format_json
(Optional)

Specifies whether the JSON will 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.
  • FORMATTEDThe features will be formatted to improve readability.
Boolean
include_z_values
(Optional)

Specifies whether the z-values of the features will be included in 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_VALUESThe z-values will be included in geometries, and the hasZ property of the JSON will be set to true.
Boolean
include_m_values
(Optional)

Specifies whether the m-values of the features will be included in 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_VALUESThe m-values will be included in geometries, and the hasM property of the JSON will be set to true.
Boolean
geoJSON
(Optional)

Specifies whether the output will be created in GeoJSON format, conforming to the GeoJSON specification.

  • GEOJSON The output will be created in GeoJSON format (.geojson file).
  • NO_GEOJSONThe output will be created in Esri JSON format (.json file). This is the default.
Boolean
outputToWGS84
(Optional)

Specifies whether the input features will be projected to the geographic coordinate system WGS_1984 with a default geographic transformation. This parameter only applies when the output is GeoJSON.

  • WGS84 Features will be projected to WGS_1984.
  • KEEP_INPUT_SRFeatures will not be projected to WGS_1984. The GeoJSON will contain a CRS tag that defines the coordinate system. This is the default.
Boolean
use_field_alias
(Optional)

Specifies whether the output file will use field aliases for feature attributes.

  • USE_FIELD_NAMEOutput feature attributes will not use field aliases; they will use field names. This is the default.
  • USE_FIELD_ALIASOutput feature attributes will use field aliases.
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.conversion.FeaturesToJSON(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 the SelectLayerByAttribute and SelectLayerByLocation functions.

# Import system modules
import arcpy

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

# Make a layer from the feature class
arcpy.management.MakeFeatureLayer("cities", "cities_lyr") 
 
# Select all cities that overlap the chihuahua polygon
arcpy.management.SelectLayerByLocation("cities_lyr", "intersect", "chihuahua", 
                                       0, "new_selection")

# Within selected features, further select only those cities that have a 
# population > 10,000   
arcpy.management.SelectLayerByAttribute("cities_lyr", "SUBSET_SELECTION", 
                                        '"population" > 10000')
 
# Convert the selected features to JSON
arcpy.conversion.FeaturesToJSON("cities_lyr", r"c:\data\myjsonfeatures.json")

Licensing information

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

Related topics