Skip to main content

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]

Metadata

Release files for json-doc 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json-doc 0.1.3
File Size Uploaded
json-doc-0.1.3.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for json-doc 0.1.3
File Interpreter ABI Platform
json_doc-0.1.3-py2-none-any.whl Python 2 none any Details

Total release size: 15.6 kB

Release files / json-doc-0.1.3.tar.gz

Download URL json-doc-0.1.3.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dc633d86a17a1f807469a59ff4488d1b163cbc40b709bc17013eaf9c72ca0cd1
BLAKE2b-256 checksum
How to use checksums
56798a5524c8494127da5833442aaaff2bc17f8dc8065c1886f42d27b33e1ce9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.13

Release files / json_doc-0.1.3-py2-none-any.whl

Download URL json_doc-0.1.3-py2-none-any.whl
Size 10.0 kB
Tags Python 2
SHA-256 checksum
How to use checksums
54ea7ff3b5da381482e8ee7d6bd53a4604b16103856d24659518992b81daef92
BLAKE2b-256 checksum
How to use checksums
7e54b53b7308c93331a0367b22cdb9e301ed090daa9937d0aced4d18d3ddc728
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.13

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page