2

Is it possible to edit the .json format, which is created by default when publishing a service on ArcGIS for Server?

For a project we have the following problem:

  • Our by default created .json for a Feature Service Layer looks e.g. like this.
  • We want to change some of these .json elements like edit the objectID name or adding another element like "api_key"?

Because there is also another group, which works simultaneously on another application, both teams should use the same data coming from an ArcGIS Server.

So....is there a way to edit the json schema?

2

You can use Python and the json module:

import json
json_data=open('arcgis.json') # your file has an error in line 36: "imageData": "blablabla",
data =json.loads(json_data)
# the result is a Python dictionary
print data.keys()
[u'drawingInfo', u'typeIdField', u'supportsRollbackOnFailureParameter', u'globalIdField', u'supportsAdvancedQueries', u'id', u'relationships', u'capabilities', u'currentVersion', u'geometryType', u'ownershipBasedAccessControlForFeatures', u'type', u'useStandardizedQueries', u'supportedQueryFormats', u'isDataVersioned', u'syncCanReturnChanges', u'allowGeometryUpdates', u'description', u'defaultVisibility', u'extent', u'objectIdField', u'htmlPopupType', u'types', u'hasM', u'displayField', u'name', u'templates', u'supportsStatistics', u'hasAttachments', u'fields', u'maxScale', u'copyrightText', u'hasZ', u'maxRecordCount', u'minScale', u'editFieldsInfo']
# you can read the values
print data['name']
u'Wastebin'
print data['extent']
{u'xmin': 845515.69519999996, u'ymin': -1860754.5734999999, u'ymax': 6795261.5813999996, u'xmax': 3884733.2325000018, u'spatialReference': {u'wkid': 102100, u'latestWkid': 3857}}
print data['extent']['xmin']
845515.69519999996
print data['extent']['spatialReference']['latestWkid']
3857
# you can change the values
data['name'] = "new"
print data['name']
u'new'
# or add new key/value
data["api_key"]= 1234
print data["api_key"]
1234
# and save the new file
with open('new.json', 'w') as outfile:
    json.dump(data, outfile)
1
  • Thanks for this. Do you have any link with further details? Because I do not really know, how to apply this script. Another question: So...modifying the json schema by using the Python script would modify the json, which is used by the corresponding ArcGIS Server Service?
    – schlomm
    Nov 19 '13 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.