This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Help us improve Python packaging - Donate today!
Project Description


jsonurl is a simple library for managing the serialisation and deserialisation of URL query strings which represent hierarchically structured data.

It will take python data structures which can be represented in JSON and convert them to flat key/value pairs for use in URL query strings, and it will take URL query strings and parse them into hierarchical data structures.

This is convenient if you wish to pass structured data around in the URL itself rather than in a POST body. This may complement a web API which also accepts JSON strings in the body of a POST request, providing equivalent functionality using GET without constructing URLs which include url-encoded json objects.


>>> import jsonurl

### Converting Data Structures

A simple flat dictionary

>>> d = {"one" : 1, "two" : 2}
>>> jsonurl.query_string(d)

A dictionary with a nested dictionary

>>> d = {"one" : {"two" : 2, "three" : 3}, "four" : 4}
>>> q = jsonurl.query_string(d)
>>> q

We can also get a flat dictionary as a proxy for the hierarchic one, if we do not want jsonurl to actually prepare the query part of the URL for us

>>> jsonurl.dict_to_args(d)
{'four': '4', 'one.three': '3', 'one.two': '2'}

We can parse the query string back into a python dictionary object

>>> jsonurl.parse_query(q)
{'four': 4, 'one': {'three': 3, 'two': 2}}

We can also serialise nested lists:

>>> d = {"one" : 1, "two" : [2,3,4]}

The flattened data structure:

>>> jsonurl.dict_to_args(d)
{'two.1': '3', 'two.0': '2', 'two.2': '4', 'one': '1'}

The query string itself:

>>> q = jsonurl.query_string(d)
>>> q

This can be comfortably parsed back into a python data structure

>>> jsonurl.parse_query(q)
{'two': [2, 3, 4], 'one': 1}

We can go on to serialise arbitrarily complex data structures

>>> d = {"one" : [ {"two" : 2, "three" : 3}, 4 ]}
>>> q = jsonurl.query_string(d)
>>> q

### Escape Characters

jsonurl will also handle url-escaping:

>>> q = {"escape_me" : "I'll need escaping"}
>>> s = jsonurl.query_string(q)
>>> s

jsonurl uses “+” for a space instead of %20 to improve readability

It also unescapes everything during parse:

>>> jsonurl.parse_query(s)
{'escape_me': "I'll need escaping"}

Since jsonurl uses “.” as its separator, dictionary keys with “.” in the name are escaped. We prefix each “.” with another during serialisation:

>>> d = {"user.names" : ["richard", "jones"]}
>>> q = jsonurl.query_string(d)
>>> q

“..” is then converted back during parsing:

>>> jsonurl.parse_query(q)
{'user.names': ['richard', 'jones']}

### Parameter Ordering

It orders the query parameters, to make it easier to read long query strings:

>>> d = {"b" : "last", "a" : [1,2,3]}
>>> jsonurl.query_string(d)
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
jsonurl-1.0.0.tar.gz (3.1 kB) Copy SHA256 Checksum SHA256 Source Mar 14, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting