Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Utility Functions for JSON Document

Project description

python-json-doc

Utility functions for JSON Document

Build Status Coverage Status GitHub license

It can handle get/set/pop/has operations on nodes

Extended set functions for lists:

  • append: appends to the list
  • extend: extends the list
  • replace: search and replace in the list
  • replace_re: search and replace in the list using regular expression

No external dependencies. Tests requires unittest2 module

Compatible with Python 2.6+ and 3.3+

Examples

doc = {
    'a': {
        'deep': {
            'nested': {
                'list': [1, 2, 3, {'dict': 'OK'}],
                'string': 'string',
                'hex': 0x010101
            }
        },
    },
    'list': [1, 2, 3]
}

# get
print json_doc_get(doc, '/a/deep/nested/list/3/dict')
>> OK

# set
print json_doc_set(doc, '/a/deep/nested/string', 'new string')['a']['deep']['nested']['string']
>> new string

# pop: target exist
print json_doc_pop(doc, '/a/deep/nested/list/2')
>> True

# pop: target doesn't exist
print json_doc_pop(doc, '/a/deep/nested/list/5')
>> False

# has item
print json_doc_has(doc, '/a/deep/nested/list/3/dict')
>> True

# has item with value
print json_doc_has(doc, '/a/deep/nested/list/3/dict', 'OK')
>> True

## List only functions

# append
print json_doc_append(doc, '/list', 4)['list']
[1, 2, 3, 4]

# extend
print json_doc_extend(doc, '/list', [5, 6, 7])['list']
[1, 2, 3, 4, 5, 6, 7]

# replace: value -> new value, search -> old value
print json_doc_replace(doc, '/list', 44, 4)['list']
[1, 2, 3, 44, 5, 6, 7]

# replace_re: -> new value, search -> regex
[111, 2, 3, 44, 5, 6, 7]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for json-doc, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size json_doc-0.1.3-py2-none-any.whl (10.0 kB) File type Wheel Python version py2 Upload date Hashes View hashes
Filename, size json-doc-0.1.3.tar.gz (5.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page