Skip to content

scalp42/jsondb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsondb

Off-memory json for large data that does not fit the memory.

Build Status

Usage

import jsondb

# Create from nothing
db = jsondb.create({})

# Add somthing
db['name'] = 'foo'
db['friends'] = []
for i in range(3):
    db['friends'].append({
        'id' : i,
        'name': chr(97 + i),
    })

# It works like an ordinary dict
assert db['name'] == 'foo'
assert db['friends'][0]['id'] == 0
assert len(db['friends']) == 3
assert db.get('nonexists', 'notfound') == 'notfound'

# Get the data
assert db.data() == {
    'name' : 'foo',
    'friends': [
        {'id' : 0, 'name' : 'a'},
        {'id' : 1, 'name' : 'b'},
        {'id' : 2, 'name' : 'c'},
    ]
}

# Query using jsonquery
db.query('$.name').getone() == 'foo'

# Iterating the query result
#   => "a b c"
for x in db.query('$.friends.name'):
    print x.data(),

# Conditonal query
#   => 'b'
print db.query('$.friends[?(@.id = 1)].name').getone()

License

Released under the BSD license.

About

Query the json data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published