Creating JSON Documents in Python OJAI

There are two ways to create JSON documents in your Python OJAI application, one of which is the preferred approach.

The preferred way to create a Python dictionary object and then pass it to the Connection.new_document() method:

json_dict = {
    "_id" : "movie0000001",
    "title" : "OJAI -- The Documentary",
    "studio" : "MapR Technologies, Inc.",
    "release_date" : "2015-09-29",
    "trailers" : {
        "teaser" : "",
        "theatrical" : ""
    "characters" : [
        "Heroic Developer", 
        "Evil Release Manager", 
        "Mad Development Manager"
    "box_office_gross" : 1000000000L
new_document = connection.new_document(dictionary=json_dict)

Alternatively, you can call Document interface methods to set fields and values:

doc = connection.new_document()
        .set('title', 'OJAI - The Documentary')
        .set('studio', 'MapR Technologies, Inc.')
        .set('release_date', ODate.parse(date_str='2015-09-29'))
        .set('trailers.teaser', '')
        .set('trailers.theatrical', '') 
        .set('characters', ['Heroic Developer', 'Evil Release Manager', 'Mad Development Manager'])
        .set('box_office_gross', 1000000000)

See the following for more details about the APIs: