def json_validator(value, context):
 if isinstance(value, (list, dict)):
  return value
 try:
  value = json.loads(value)
 except ValueError:
  raise df.Invalid('Cannot parse JSON')
 return value

def json_validator ( value , context ) : if isinstance ( value , ( list , dict ) ) : return value try : value = json . loads ( value ) except ValueError : raise df . Invalid ( 'Cannot parse JSON' ) return value
validate and parse a json value .