def clean_json(value, of_type):
 if (not value.strip()):
  return json.dumps(of_type())
 try:
  value_python = json.loads(value)
 except ValueError as err:
  raise ValidationError('Invalid JSON: {}'.format(err.message))
 if (not isinstance(value_python, of_type)):
  raise ValidationError('Expected a JSON {}'.format(of_type))
 return json.dumps(value_python, indent=4)

def clean_json ( value , of_type ) : if ( not value . strip ( ) ) : return json . dumps ( of_type ( ) ) try : value_python = json . loads ( value ) except ValueError as err : raise ValidationError ( 'Invalid JSON: {}' . format ( err . message ) ) if ( not isinstance ( value_python , of_type ) ) : raise ValidationError ( 'Expected a JSON {}' . format ( of_type ) ) return json . dumps ( value_python , indent = 4 )
simple helper method to parse and clean json .