Is Survey123 webhook sending valid JSON?

02-23-2023 02:31 PM
Occasional Contributor

This is a super nitpicky question, so apologies in advance.

It seems like most times I deal with JSON, it conforms to the ECMA spec which states that strings must be contained with the double-quote character ("). However, most (not all!), of the info I get in JSON from Survey123 is in single quotes. This gets weirder if the said string contains a single quote, as then the entire string gets placed in double-quotes, per the spec, while every other string remains in single-quotes.

By way of example:


  'full_name': "Roger O'Leary", 
  'email_address': ''


Programmatically, depending on what I'm doing with said data, I will get an error such as:

Expecting property name enclosed in double quotes: line 2 column 3 

Obviously this can be fixed by running some validation, replacing single quotes with double quotes, and escaping legit single-quotes. But I'm curious if there's a better way (in Python at the moment...) or if I'm not retrieving the JSON from the webhook properly to begin with (in azure function app with req.get_json() example below)


import logging
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    jsonString = req.get_json()
    logging.error(f"The json is: {jsonString}")


Full JSON example below (raw, unformatted as received):

{'applyEdits': [{'id': 0, 'adds': [{'attributes': {'problem_type_ordered_by_most_co': 'Road Problem', 'land_use_problems_type': None, 'describe_the_problem': 'Feb. 23 Roads test.', 'address': '1200-1298 Hayes Ave, Fairbanks, Alaska, 99709', 'full_name': "Roger O'Leary", 'email_address': '', 'globalid': '{603034E6-6360-41D2-88D1-B4F7D11C97B5}'}, 'geometry': {'geometryType': 'esriGeometryPoint', 'x': -147.80548593192015, 'y': 64.8548894970469, 'spatialReference': {'wkid': 4326}}}], 'attachments': {'adds': [{'globalId': '{1D9FB73D-E791-4C56-888D-A0C583CC45F9}', 'parentGlobalId': '{603034E6-6360-41D2-88D1-B4F7D11C97B5}', 'keywords': 'if_availale_add_photo', 'contentType': 'image/jpeg', 'name': 'Ridgepoint+ditching.jpg', 'uploadId': 'df6ade0f739a4999b6bb29323dd13f12'}]}}], 'feature': {'attributes': {'problem_type_ordered_by_most_co': 'Road Problem', 'land_use_problems_type': None, 'describe_the_problem': 'Feb. 23 Roads test.', 'location_of_problemDefault': None, 'location_of_problemRoads': {'geometryType': 'esriGeometryPoint', 'x': -147.80548593192015, 'y': 64.8548894970469, 'spatialReference': {'wkid': 4326}}, 'location_of_problemTransfer': None, 'location_of_problemTransport': None, 'location_of_problemParks': None, 'location_of_problemWater': None, 'address': '1200-1298 Hayes Ave, Fairbanks, Alaska, 99709', 'full_name': "Roger O'Leary", 'email_address': '', 'globalid': '{603034E6-6360-41D2-88D1-B4F7D11C97B5}', 'objectid': 430}, 'geometry': {'geometryType': 'esriGeometryPoint', 'x': -147.80548593192015, 'y': 64.8548894970469, 'spatialReference': {'wkid': 4326}}, 'layerInfo': {'id': 0, 'name': 'survey', 'type': 'Feature Layer', 'globalIdField': 'globalid', 'objectIdField': 'objectid', 'relationships': []}, 'result': {'globalId': '{603034E6-6360-41D2-88D1-B4F7D11C97B5}', 'objectId': 430, 'uniqueId': 430, 'success': True}, 'attachments': {'if_availale_add_photo': [{'id': 145, 'url': '', 'name': 'Ridgepoint+ditching.jpg', 'size': 886497, 'contentType': 'image/jpeg', 'keywords': 'if_availale_add_photo', 'globalId': '{1D9FB73D-E791-4C56-888D-A0C583CC45F9}', 'parentGlobalId': '{603034E6-6360-41D2-88D1-B4F7D11C97B5}'}]}}, 'eventType': 'addData'}


Roger Asbury
Analyst/Programmer - Fairbanks North Star Borough
0 Kudos
0 Replies