Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Map and parse JSON text to python dict

Project Description

# About json-mapper

Package for map and parse JSON text to python dict.

For example, to bring to readable form of responses from the Rest API.

# Usage example

Suppose we have such a terrible JSON dump:

```python
{
"ApiResponse": {
"ApiResponseWrapper": {
"HotelsResponse": [
{
"Country": "Russia",
"HotelId": "1234",
"HotelName": "Space Hotel",
"Photos": [
{
"BigUrl": "http://www.image.url.com",
"ThumbnailUrl": "http://www.image.url.com"
},
... other photos ...
],
"RoomsResponse": [
{
"BedsCount": "1",
"RoomId": "12312"
},
... other rooms ...
]
},
... other hotels ...
],
"ResponseTimestamp": "2342423423423423",
"SessionId": "0ABAA840-F6EC-6913-A1C2-7341899060B6"
},
"SomeProperty": "SomeData"
}
}
```

Example to map the his pretty:

```python
import json
from json_mapper.mapper import map_json

json_data = json.loads(open('dump.json').read())

mapping_config = {
'ApiResponse.ApiResponseWrapper': {
'ResponseTimestamp': 'last_update',

'{loop=>hotels} HotelsResponse': {
'HotelId': 'id',
'Country': 'country',

'{loop=>photos} Photos': 'BigUrl',

'{loop=>rooms} RoomsResponse': {
'RoomId': 'id',
'BedsCount': 'beds'
}
}
}
}

result = map_json(mapping_config, json_data)

>>> pprint(result)
{'hotels': [{'country': u'Russia',
'id': u'1234',
'photos': [u'http://www.image.url.com',
u'http://www.image.url.com'],
'rooms': [{'beds': u'1', 'id': u'12312'},
{'beds': u'1', 'id': u'12312'}]},
{'country': u'Russia',
'id': u'1234',
'photos': [u'http://www.image.url.com',
u'http://www.image.url.com'],
'rooms': [{'beds': u'1', 'id': u'12312'},
{'beds': u'1', 'id': u'12312'}]}],
'last_update': u'2342423423423423'}
```

See full example in tests directory.

Release History

This version
History Node

0.1.15

History Node

0.1.14

History Node

0.1.13

History Node

0.1.12

History Node

0.1.11

History Node

0.1.10

History Node

0.1.9

History Node

0.1.8

History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
json-mapper-0.1.15.tar.gz
(4.3 kB) Copy SHA256 Hash SHA256
Source None Oct 26, 2012

Supported By

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 Google Google Cloud Servers DreamHost DreamHost Log Hosting