Official JSON formats

10307
5
04-30-2012 02:02 PM
DenisLapierre
New Contributor II
Hi everyone,

I would like to know where can I find the real official JSON formats with versions.
Is there a real standard somewhere?
Does ESRI uses that standard?
Where can I find the official ESRI JSON formats?
What standard does JSON.stringify() uses?

I have found it very difficult to find reliable information on this.

BTW:
My problem is that I'm trying to call a geoprocessing service on ArcGIS 10.0, but the translation from my javascript FeatureSet to JSON is not proper to what the greopressing service expect. In the request, the input has a different format and has empty values.
Service I'm trying to call : http://oxpgisws01d.env.gov.ab.ca/ArcGIS/rest/services/IWCP/IWCP/GPServer/PointsLocationValidation

Thanks
5 Replies
AndyGup
Esri Regular Contributor
@petaques, Hi, I'm not a JSON expert so I can't answer most of your questions. However, you can find detailed information on our JSON response syntax. For that information, please consult the ArcGIS Server REST API specifcation:

http://help.arcgis.com/EN/arcgisserver/10.0/apis/rest/index.html

Also, here's a few other links that I've found to be helpful:

http://json.org/
http://www.json.org/js.html


-Andy
0 Kudos
DenisLapierre
New Contributor II
Hi, so far I didn't find any real Official JSON format (if that exist).

I've found the ESRI JSON input format expected by a geoprocessing service for ArcGIS 10.0.
http://help.arcgis.com/EN/arcgisserver/10.0/apis/rest/index.html
So I know exactly what the geoprocessing service expects.

I've also seen how a featureSet should be sent to a geoprocessing service through the submitJob function of the esri.tasks.Geoprocessor.
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/geoprocessor.htm

My problem is to figure out, where does that geoprocessor find its toJson function for a featureSet.

ESRI says that the format expected should be some like this :
{ 
"geometryType" : "esriGeometryPoint",
"spatialReference" : {"wkid" : 4326},
"features"  : [
{
    "geometry" : {"x" : -104.44, "y" : 34.83},
    "attributes" : {"Id" : 43, "Name" : "Feature 1"}
},
{
    "geometry" : {"x" : -100.65, "y" : 33.69},
    "attributes" : {"Id" : 67, "Name" : "Feature 2"}
}
]
}


But then, the geoprocessor object create the JSON from my featureSet like this:
{
"fields":[],
"geometryType":"esriGeometryPoint",
"features":[
{
  "geometry":{"x":678731.422659788,"y":6221057.36591139,"spatialReference":{"wkid":3400}},
  "attributes":{"ID":0,"NAME":"Main Camp","TYPE":"Permanent","LATITUDE":"56.123456","LONGITUDE":"-112.12345678","LOCAT_VALID":"Valid","isAlone":true}
}
],
"sr":{"wkid":3400}
}


Althought the JSON.stringify() method give me this :
{
"features":[
{
  "geometry":{"type":"point","x":678731.422659788,"y":6221057.36591139,"spatialReference":{"wkid":3400}},
  "symbol":null,
  "attributes":{"ID":0,"NAME":"Main Camp","TYPE":"Permanent","LATITUDE":"56.123456","LONGITUDE":"-112.12345678","LOCAT_VALID":"Valid","isAlone":true},
  "infoTemplate":{"title":"Main Camp","content":"Latitude: 56.123456<br>Longitude: -112.12345678"}
}
],
"geometryType":"esriGeometryPoint",
"spatialReference":{"wkid":3400}
}


I've tried to call the service from the rest end point with both JSON featureSet and I found out why the JSON object created by the geoprocessor does not work. It simply that, as you can notice, the spatial reference from the geoprocessor is noted as
"sr":{"wkid":3400}
while form the stringify method it is noted as
"spatialReference":{"wkid":3400}
which is the expected format.

I'm wondering if this is normal and there is just something I'm missing, or is it simply a bug from esri.tasks.geoprocessor.
That is why I'd like to know what does the esri.tasks.geoprocessor uses for the purpose of converting FeatureSet to JSON and how can I work around that problem.

If anyone has encountered that problem or has a hint on how to solve this, it'd be appreciated.
Thank you
0 Kudos
JeffPace
MVP Alum
i use http://json.org/
and the validator at

http://jsonformatter.curiousconcept.com/


So far pretty straight forward, only surprise was that comments are not supported!
You cannot have //comments in json

you need to actually add a comments key:value pair


Hi, so far I didn't find any real Official JSON format (if that exist).

I've found the ESRI JSON input format expected by a geoprocessing service for ArcGIS 10.0.
http://help.arcgis.com/EN/arcgisserver/10.0/apis/rest/index.html
So I know exactly what the geoprocessing service expects.

I've also seen how a featureSet should be sent to a geoprocessing service through the submitJob function of the esri.tasks.Geoprocessor.
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/geoprocessor.htm

My problem is to figure out, where does that geoprocessor find its toJson function for a featureSet.

ESRI says that the format expected should be some like this :
{ 
"geometryType" : "esriGeometryPoint",
"spatialReference" : {"wkid" : 4326},
"features"  : [
{
    "geometry" : {"x" : -104.44, "y" : 34.83},
    "attributes" : {"Id" : 43, "Name" : "Feature 1"}
},
{
    "geometry" : {"x" : -100.65, "y" : 33.69},
    "attributes" : {"Id" : 67, "Name" : "Feature 2"}
}
]
}


But then, the geoprocessor object create the JSON from my featureSet like this:
{
"fields":[],
"geometryType":"esriGeometryPoint",
"features":[
{
  "geometry":{"x":678731.422659788,"y":6221057.36591139,"spatialReference":{"wkid":3400}},
  "attributes":{"ID":0,"NAME":"Main Camp","TYPE":"Permanent","LATITUDE":"56.123456","LONGITUDE":"-112.12345678","LOCAT_VALID":"Valid","isAlone":true}
}
],
"sr":{"wkid":3400}
}


Althought the JSON.stringify() method give me this :
{
"features":[
{
  "geometry":{"type":"point","x":678731.422659788,"y":6221057.36591139,"spatialReference":{"wkid":3400}},
  "symbol":null,
  "attributes":{"ID":0,"NAME":"Main Camp","TYPE":"Permanent","LATITUDE":"56.123456","LONGITUDE":"-112.12345678","LOCAT_VALID":"Valid","isAlone":true},
  "infoTemplate":{"title":"Main Camp","content":"Latitude: 56.123456<br>Longitude: -112.12345678"}
}
],
"geometryType":"esriGeometryPoint",
"spatialReference":{"wkid":3400}
}


I've tried to call the service from the rest end point with both JSON featureSet and I found out why the JSON object created by the geoprocessor does not work. It simply that, as you can notice, the spatial reference from the geoprocessor is noted as
"sr":{"wkid":3400}
while form the stringify method it is noted as
"spatialReference":{"wkid":3400}
which is the expected format.

I'm wondering if this is normal and there is just something I'm missing, or is it simply a bug from esri.tasks.geoprocessor.
That is why I'd like to know what does the esri.tasks.geoprocessor uses for the purpose of converting FeatureSet to JSON and how can I work around that problem.

If anyone has encountered that problem or has a hint on how to solve this, it'd be appreciated.
Thank you
0 Kudos
AndyGup
Esri Regular Contributor
Jeff, here's Douglas Crockford's comment on why he removed comments from JSON: https://plus.google.com/118095276221607585885/posts/RK8qyGVaGSr

-Andy
0 Kudos
JeffPace
MVP Alum
Jeff, here's Douglas Crockford's comment on why he removed comments from JSON: https://plus.google.com/118095276221607585885/posts/RK8qyGVaGSr

-Andy


THanks for the link.  IT really isnt a big deal, more of just a watershed moment when "why is my json always invalid" is oh - no comments allowed!!
0 Kudos