ArcGIS Pro 2.7 API Reference Guide
ImportFromJSON Method (IGeometryEngine)
Example 

ArcGIS.Core.Geometry Namespace > IGeometryEngine Interface : ImportFromJSON Method
A combination of JSONImportFlags which determines how the geometry is imported.
The input JSON string. If the spatial reference information is in the string, then the output geometry will have the spatial reference associated with it.
Creates a geometry from the input JSON string.
Syntax
Function ImportFromJSON( _
   ByVal importFlags As JSONImportFlags, _
   ByVal jsonString As String _
) As Geometry

Parameters

importFlags
A combination of JSONImportFlags which determines how the geometry is imported.
jsonString
The input JSON string. If the spatial reference information is in the string, then the output geometry will have the spatial reference associated with it.

Return Value

A Geometry that corresponds to the jsonString.
Exceptions
ExceptionDescription
jsonString is null or empty.
Example
// MapPoint
string inputString = "{\"x\":1,\"y\":2,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}";
Geometry geometry = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, inputString);

MapPoint importPoint = geometry as MapPoint;
// importPoint = 1, 2
// importPoint.SpatialReference.WKid = 4326

// use the MapPointBuilder convenience method
MapPoint importPoint2 = MapPointBuilder.FromJson(inputString);
// importPoint2 = 1, 2
// impointPoint2.SpatialReference.Wkid = 4326

string outputString = GeometryEngine.Instance.ExportToJSON(JSONExportFlags.jsonExportDefaults, importPoint);
// outputString =  "{\"x\":1,\"y\":2,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}"

string outputString2 = importPoint.ToJson();

inputString = "{\"spatialReference\":{\"wkid\":4326},\"z\":3,\"m\":4,\"x\":1,\"y\":2}";
importPoint = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, inputString) as MapPoint;
// importPoint.HasM = true
// importPoint.HasZ = true
// importPoint.X = 1
// importPoint.Y = 2
// importPoint.M = 4
// importPoint.Z = 3

importPoint2 = MapPointBuilder.FromJson(inputString);

// export to json - skip spatial reference
outputString = GeometryEngine.Instance.ExportToJSON(JSONExportFlags.jsonExportSkipCRS, importPoint);
// outputString = "{\"x\":1,\"y\":2,\"z\":3,\"m\":4}"

// export from mappoint, skipping the sr - same as GeometryEngine.Instance.ExportToJSON w JSONExportFlags.jsonExportSkipCRS
outputString2 = importPoint.ToJson(true);

//
// Multipoint
//
List<Coordinate2D> coords = new List<Coordinate2D>()
{
  new Coordinate2D(100, 200),
  new Coordinate2D(201, 300),
  new Coordinate2D(301, 400),
  new Coordinate2D(401, 500)
};

Multipoint multipoint = MultipointBuilder.CreateMultipoint(coords, SpatialReferences.WebMercator);

inputString = "{\"points\":[[100,200],[201,300],[301,400],[401,500]],\"spatialReference\":{\"wkid\":3857}}";
Multipoint importMultipoint = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, inputString) as Multipoint;
// importMultipoint.IsEqual(multipoint) = true

ReadOnlyPointCollection points = importMultipoint.Points;
// points.Count = 4
// points[0] = 100, 200
// points[1] = 201, 300
// points[2] = 301, 400
// points[3] = 401, 500

// use the Multipointbuilder convenience method
Multipoint importMultipoint2 = MultipointBuilder.FromJson(inputString);
// importMultipoint2.IsEqual(multipoint) = true

// export to json
outputString = GeometryEngine.Instance.ExportToJSON(JSONExportFlags.jsonExportDefaults, multipoint);
// outputString = inputString

// or use the multipoint itself
outputString2 = multipoint.ToJson();

//
// Polyline
//
Polyline polyline = PolylineBuilder.CreatePolyline(coords, SpatialReferences.WebMercator);

// export without the spatial reference
outputString = GeometryEngine.Instance.ExportToJSON(JSONExportFlags.jsonExportSkipCRS, polyline);
// import
geometry = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, outputString);
Polyline importPolyline = geometry as Polyline;
// importPolyline.SpatialReference = null


points = importPolyline.Points;
// points.Count = 4
// points[0] = 100, 200
// points[1] = 201, 300
// points[2] = 301, 400
// points[3] = 401, 500

// use the polylineBuilder convenience method 
Polyline importPolyline2 = PolylineBuilder.FromJson(outputString);
// importPolyline2 = importPolyline

outputString2 = importPolyline2.ToJson();
// outputString2 = outputString

//
// Polygon
//
Polygon polygon = PolygonBuilder.CreatePolygon(coords, SpatialReferences.WebMercator);

// export without the spatial reference
outputString = GeometryEngine.Instance.ExportToJSON(JSONExportFlags.jsonExportSkipCRS, polygon);
// import
geometry = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, outputString);

Polygon importPolygon = geometry as Polygon;
// importPolygon.SpatialReference = null
points = importPolygon.Points;
// points.Count = 5

// polygonBuilder convenience method
Polygon importPolyon2 = PolygonBuilder.FromJson(outputString);
// importPolygon2 = importPolygon

// export from the polygon
outputString2 = importPolyon2.ToJson(true);

// Empty polygon
polygon = PolygonBuilder.CreatePolygon(SpatialReferences.WebMercator);
outputString = GeometryEngine.Instance.ExportToJSON(JSONExportFlags.jsonExportDefaults, polygon);
importPolygon = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, outputString) as Polygon;

// importPolygon.IsEmpty = true
// importPolygon.SpatialReference.Wkid = 3857
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

IGeometryEngine Interface
IGeometryEngine Members