1 from django import forms
2 from django.core.exceptions import ValidationError
3 from django.utils import simplejson as json
4 from philo.validators import json_validator
7 __all__ = ('JSONFormField',)
10 class JSONFormField(forms.Field):
11 default_validators = [json_validator]
13 def clean(self, value):
14 if value == '' and not self.required:
17 return json.loads(value)
19 raise ValidationError(u'JSON decode error: %s' % e)