json: check for missing key before appending any field