Skip to main content

JSON Processor - Convert one JSON to another

Project description

https://travis-ci.org/huntflow/json-processor.svg?branch=master https://codecov.io/gh/huntflow/json-processor/branch/master/graph/badge.svg

Simply convert one JSON to another.

  • Easy to use. Create a simple JSON conversion schema and pass it to processor
  • Rich. It uses jsonpointer so you can create complex processors

Example

from json_processor import json_process

schema = {
    "type": "object",
    "value": {
        "simple_key": "Just a string",
        "values": {
            "type": "array",
            "from": {
                "type": "jsonpointer",
                "value": "/data/items"
            },
            "value": {
                "type": "object",
                "value": {
                    "id": {
                        "type": "jsonpointer",
                        "value": "/$value/foreign",
                        "cast": "integer"
                    },
                    "name": {
                        "type": "jsonpointer",
                        "value": "/$value/name"
                    }
                }
            }
        }
    }
}

data = {
    "data": {
        "items": [
            {
                "foreign": "100",
                "name": "Item 1"
            },
            {
                "foreign": "150",
                "name": "Item 2"
            }
        ]
    }
}

print(json_process(schema, data))

# Outputs:
# {'simple_key': 'Just a string', 'values': [{'id': 100, 'name': 'Item 1'}, {'id': 150, 'name': 'Item 2'}]}

Installation

From PyPi

pip install json_processor

Command line tool

After installation you can use json_process utility:

json_process <schema_file> <json_file>

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-processor, version 0.0.9
Filename, size File type Python version Upload date Hashes
Filename, size json_processor-0.0.9.tar.gz (6.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page