When I log 'export_json' to the console prior to send the data via ajax the data is exactly the way I want it to be. It contains all the features I want. However, when I print the data to flask or write it to a JSON file the features are missing.The code I have shown here ends up writing nothing to the json file I've created but i've gotten it to write everything but the features before (e.g. what I said I had displayed in powershell down below). Does anyone know why the JSON object POSTed doesn't contain features? Please let me know if i'm not being descriptive enough!
Javsacript
console.log(export_json)
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=UTF-8',
data: export_json,
success: function(data){console.log(data)}
});
Python
@app.route('/interactive', methods=['GET', 'POST', 'OPTIONS'])
def interactive():
try:
if request.method == 'POST':
with open(output_json, 'w') as outfile:
json.dump(request.get_json(force=True), outfile)
resp = Response('whathaver')
return resp
except Exception, e:
return (str(e))
if __name__ == '__main__':
app.run(debug=True)
Here's what's displayed in Powershell:
{"displayFieldName":"","fieldAliases":{"FID":"FID","Name_1":"Name_1","LL_X_DD":"LL_X_DD","LL_Y_DD":"LL_Y_DD","Shape_Area
":"Shape_Area","PCT_LAND":"PCT_LAND"},"geometryType":"esriGeometryPolygon","spatialReference":{"wkid":4326,"latestWkid":
4326},"fields":[{"name":"FID","type":"esriFieldTypeOID","alias":"FID"},{"name":"Name_1","type":"esriFieldTypeString","al
ias":"Name_1","length":254},{"name":"LL_X_DD","type":"esriFieldTypeDouble","alias":"LL_X_DD"},{"name":"LL_Y_DD","type":"
esriFieldTypeDouble","alias":"LL_Y_DD"},{"name":"Shape_Area","type":"esriFieldTypeDouble","alias":"Shape_Area"},{"name":
"PCT_LAND","type":"esriFieldTypeInteger","alias":"PCT_LAND"}],"features":[]}
There should be features in "features" at the end there. Those features are present when I log 'export_json' to the console though but not present here. Any help would be greatly appreciated!
'export_json' how it appears in the console:
[object Object]
{
[functions]: ,
__proto__: { },
displayFieldName: "",
features: [ ],
fieldAliases: { },
fields: [ ],
geometryType: "esriGeometryPolygon",
spatialReference: { }
}
[object Object]
{
[functions]: ,
__proto__: { },
displayFieldName: "",
features: [
0: { },
1: { },
2: { },
3: { },
4: { },
5: { },
6: { },
7: { },
8: { },
9: { },
10: { },
11: { },
12: { },
13: { },
14: { },
15: { },
16: { },
17: { },
18: { },
19: { },
20: { },
length: 21
],
fieldAliases: { },
fields: [ ],
geometryType: "esriGeometryPolygon",
spatialReference: {
[functions]: ,
__proto__: { },
latestWkid: 4326,
wkid: 4326
}
}
[object Object]
{
[functions]: ,
__proto__: { },
displayFieldName: "",
features: [
0: {
[functions]: ,
__proto__: {
[functions]: ,
__proto__: null
},
attributes: {
[functions]: ,
__proto__: { },
FID: 0,
LL_X_DD: 6,
LL_Y_DD: 0,
Name_1: "N0000E00600",
PCT_LAND: 2,
Shape_Area: 0.25
},
geometry: {
[functions]: ,
__proto__: {
[functions]: ,
__proto__: null
},
rings: [
0: [
0: [
0: 6.500000000000057,
1: 5.684341886080802e-14,
length: 2
],
1: [ ],
2: [ ],
3: [ ],
4: [ ],
length: 5
],
length: 1
]
}
},
1: { },
2: { },
3: { },
4: { },
5: { },
6: { },
7: { },
8: { },
9: { },
10: { },
11: { },
12: { },
13: { },
14: { },
15: { },
16: { },
17: { },
18: { },
19: { },
20: { },
length: 21
],
fieldAliases: { },
fields: [ ],
geometryType: "esriGeometryPolygon",
spatialReference: { }
}