Python json schema that extracts parameters
<p>I need to parse requests to a single url that are coming in JSON, but in several different formats. For example, some have timestamp noted as <code>timestamp</code> attr, others as <code>unixtime</code> etc. So i want to create json schemas for all types of requests that not only validate incoming JSONs but also extract their parameters from specified places. Is there a library that can do that?</p>

<p>Example:</p>

<p>If I could define a schema that would look something like this</p>

<pre><code>schema = {
    "type" : "object",
    "properties" : {
        "price" : {
            "type" : "number",
            "mapped_name": "product_price"
        },
        "name" : {
            "type" : "string",
            "mapped_name": "product_name"

        },
        "added_at":{
            "type" : "int",
            "mapped_name": "timestamp"

        },
    },
}
</code></pre>

<p>and then apply it to a dict </p>

<pre><code>request = {
    "name" : "Eggs",
    "price" : 34.99,
    'added_at': 1234567
}
</code></pre>

<p>by some magical function</p>

<pre><code>params = validate_and_extract(request, schema)
</code></pre>

<p>I want <code>params</code> to have mapped values there:</p>

<pre><code>{"mapped_name": "Eggs", "product_price": 34.99, "timestamp": 1234567}
</code></pre>

<p>so this is a module I'm looking for. And it should support nested dicts in <code>request</code>, not just flat dicts.</p>

<p>See <a href="http://json-schema.org" rel="nofollow">http://json-schema.org</a></p>

<p>This doesn't look like a Python question. </p>

python json