how to validate mongodb_id field with JSON schema?

2,070 views
Skip to first unread message

Hooman Korasani

unread,
Jun 10, 2013, 12:55:16 PM6/10/13
to jsons...@googlegroups.com
if you have worked with Mongodb you know of the key field that is defined as an objectid()

I have problems validating that field. This is how my schema looks like:

schema = {
          "type" : "object",
          "properties" : {
                            "user_id" : {
                                         "type": "object",
                                         "properties": {
                                                        "$oid" : { "type": "string" }
                                                        }
                            },                         
                            "notes" : {"type" : "string"},                                                
                          },
          "required": ["user_id"]
          }

This is the error message I am getting:

jsonschema.exceptions.ValidationError

ValidationError: ObjectId('51b5fbaa38178440fcc5859a') is not of type 'object' Failed validating 'type' in schema['properties']['user_id']: {'properties': {'$oid': {'type': 'string'}}, 'type': 'object'} On instance['user_id']: ObjectId('51b5fbaa38178440fcc5859a')


Any suggestions?

Many Thanks,
Hooman

Julian Berman

unread,
Jun 12, 2013, 11:40:51 AM6/12/13
to Hooman Korasani, jsons...@googlegroups.com

Object in JSON Schema refers to a JSON object (which corresponds to a Python dict) not a Python object.

ObjectIDs aren't dicts, so they won't pass that. Right now there isn't a way to make assertions about types other than the ones that are valid JSON. I'd recommend just removing that type check.

Cheers
Julian

--
You received this message because you are subscribed to the Google Groups "jsonschema - An implementation of JSON Schema for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema+...@googlegroups.com.
To post to this group, send email to jsons...@googlegroups.com.
 
 
Reply all
Reply to author
Forward
0 new messages