Using Geometry.fromJSON() gives unexpected results

05-07-2020 07:42 AM
Esri Contributor

I am trying to use Geometry.fromJSON() in the ArcGIS JSAPI 4.x to return a Point or an Extent geometry and I am getting some unexpected results.

Here is what I have tried.

const point = Geometry.fromJSON({x: 10, y: 10, spatialReference: {wkid: 4326}})
const point = Geometry.fromJSON({type: "point", x: 10, y: 10, spatialReference: {wkid: 4326}})
const point = Geometry.fromJSON(JSON.stringify({x: 10, y: 10, spatialReference: {wkid: 4326}}))
const point = Geometry.fromJSON({"x": 10, "y": 10, "spatialReference": {"wkid": 4326}})
const point = Geometry.fromJSON('{"x": 10, "y": 10, "spatialReference": {"wkid": 4326}}')

Here is the result in the console.


Should I be able to get a Point geometry with the JSON I am using with Geometry.fromJSON()?

My goal would be to do the following...


...using valid JSON for a Point or an Extent.

0 Kudos
2 Replies
Esri Contributor

Hi Eric, I would try using Point.fromJSON() instead.

Esri Contributor


Thank you for the reply. I did notice that worked, and I forgot to add that detail to my post. The JSON will be describing a point or an extent so I was hoping that Geomery.fromJSON() would be able to create a Point from point JSON and an Extent from extent JSON. Am I using Geometry.fromJSON() incorrectly? 

0 Kudos