🌡 Javascript like JSON object mapping in Python
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
pickly
.gitignore
.travis.yml
LICENSE
Makefile
README.md
setup.py
test_pickly.py

README.md

Pickly 🌡

Build Status codecov

Pickly is a tiny library for JSON object mapping in Python. It you allows to access JSON attributes like plain old objects just like in Javascript. There is no need to deal with dictionaries anymore πŸŽ‰

Installation

The recommended installation method is pip:

$ pip install pickly 

Usage

from pickly import Pickly

json = '''
  {
    "name": "Newman Gates",
    "tags": [
      "sunt",
      "cillum"
    ],
    "friends": [
      {
        "id": 0,
        "name": "Greer Bentley"
      },
      {
        "id": 1,
        "name": "Ebony Montgomery"
      }
    ]
  }
'''
# Woallah, you are ready! πŸŽ‰πŸ°
obj = Pickly(json)

# Print an object to see what's inside
print obj.friends # [{"id": 0, "name": "Greer Bentley"}, {"id": 1, "name": "Ebony Montgomery"}]

print obj.tags[0] # sunt

obj.name # Newman Gates

# Iterate through lists
for item in obj.friends:
    item.name

πŸ‘‰ Using Pickly with Requests

from pickly import Pickly
import requests

res = requests.get('http://jsonplaceholder.typicode.com/posts')
obj = Pickly(res.text) # You are ready to roll πŸ”₯

for item in obj:
    item.title

πŸ‘‰ Using Pickly with a JSON file

from pickly import Pickly

with open('file.json', 'r') as fp:
    obj = Pickly(fp.text())

obj.foo.name

Thank You πŸ˜€

Thanks for checking this library out! I hope you find it useful.

There's always room for improvement. Feel free to open an issue so we can make Pickly better!