Label | Explanation | Data Type |
Input Features
| The features that will be converted 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.
| Boolean |
Include Z Values (Optional) | Specifies whether the z-values of the features will be included in the JSON.
| Boolean |
Include M Values (Optional) | Specifies whether the m-values of the features will be included in the JSON.
| Boolean |
Output to GeoJSON (Optional) | Specifies whether the output will be created in GeoJSON format or Esri JSON format.
| Boolean |
Project to WGS84 (Optional) | Specifies whether the input features will be projected to the WGS84 geographic coordinate system with a default geographic transformation. This parameter only applies when the output is GeoJSON.
| Boolean |
Use field aliases
(Optional) | Specifies whether the output file will use field aliases for feature attributes.
| Boolean |
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 can use the Project to WGS84 parameter to project the input features to the WGS84 coordinate system, which is the standard for the GeoJSON specification. A default geographic transformation will be applied if necessary. If this parameter 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 use field aliases in the output rather than field names.
The output file cannot exceed 4 GB in size. Reduce the input data if it is too large.
Parameters
arcpy.conversion.FeaturesToJSON(in_features, out_json_file, {format_json}, {include_z_values}, {include_m_values}, {geoJSON}, {outputToWGS84}, {use_field_alias})
Name | Explanation | Data Type |
in_features | The features that will be converted 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.
| Boolean |
include_z_values (Optional) | Specifies whether the z-values of the features will be included in the JSON.
| Boolean |
include_m_values (Optional) | Specifies whether the m-values of the features will be included in the JSON.
| Boolean |
geoJSON (Optional) | Specifies whether the output will be created in GeoJSON format, conforming to the GeoJSON specification or Esri JSON format,.
| Boolean |
outputToWGS84 (Optional) | Specifies whether the input features will be projected to the WGS84 geographic coordinate system with a default geographic transformation. This parameter only applies when the output is GeoJSON.
| Boolean |
use_field_alias (Optional) | Specifies whether the output file will use field aliases for feature attributes.
| Boolean |
Code sample
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.conversion.FeaturesToJSON(os.path.join("outgdb.gdb", "myfeatures"),
"myjsonfeatures.json")
arcpy.conversion.FeaturesToJSON(os.path.join("outgdb.gdb", "myfeatures"),
"mypjsonfeatures.json", "FORMATTED")
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")
Convert a subset of features to JSON using the SelectLayerByLocation and SelectLayerByAttribute functions first.
# 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")