I have a JSON string from which I am trying to extract a property value using Python as shown below:
def extract_property(node, to_extract):
data, stat = zk.get(node)
jsonString = data.decode("utf-8")
jStr = json.loads(jsonString)
return jStr[to_extract]
Now it is possible, the property value that I am trying to extract doesn't exist in that JSON string so it will fail. How can I return empty string if property doesn't exist at all in the JSON string.
This line can fail if property doesn't exist.
return jStr[to_extract]