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