Skip to main content

Handle JSON like data structures with a "repr(...)" fallback, e.g. for MongoDB types

Project description

json-repr

Pretty print JSON like data structures with a "repr(...)" fallback, e.g. for MongoDB types

Usage

import json_repr

# JSON: Legacy Mongo Shell Format
original_source = """{
    "_id": ObjectId("507f1f77bcf86cd799439011"),
    "employees": [
        {
            "firstName": "Alice",
            "middleName": null,
            "id": NumberInt(1),
            "active": true
        },
        {
            "firstName": "Bob",
            "middleName": null,
            "id": NumberInt(2),
            "active": false
        }
    ]
}"""

document = json_repr.eval_mongo_db_json(original_source)

print(document["employees"][0])

dumped_source = json_repr.dumps(document)
print(dumped_source)

print(dumped_source == original_source)

MongoDB

Currently supported (legacy) mongo shell types:

  • ObjectId
  • NumberInt
  • NumberLong
  • NumberDecimal

and

  • null
  • true
  • false

Project details


Download files

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

Source Distribution

json_repr-1.1.12.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

json_repr-1.1.12-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page