day 11 - json_util

This commit is contained in:
Brendan McDevitt 2018-01-18 00:19:52 -05:00
parent 0636999ac9
commit 00d595507d

View file

@ -0,0 +1,34 @@
---
layout: post
title: "day 11"
date: 2018-01-17
categories: programming
---
# 100 Days of Code
### Day 11:
Took a break on the weekend, but I am back at it. Today, I made a class for
decoding json data. Here is the code. I can use this with my xonsh shell now so
its proving to be useful.
```python
import os
import json
from pprint import pprint
class JsonUtils(object):
""" Json utility library """
def decode(self, json_file):
""" Decode a json string or file that contains json """
if os.path.isfile(json_file):
with open(json_file, 'r'):
data = json.load(json_file)
return pprint(data)
else:
data = json.loads(json_file)
return pprint(data)
```