added json to yaml script · optionalg/python-scripts@24d6113 · GitHub
Skip to content

Commit 24d6113

Browse files
committed
added json to yaml script
1 parent b287df6 commit 24d6113

4 files changed

Lines changed: 51 additions & 11 deletions

File tree

29_json_test.json

Lines changed: 31 additions & 0 deletions

29_json_to_yaml.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sys
2+
import json
3+
import yaml
4+
5+
"""
6+
Example usage:
7+
8+
$ python 29_json_to_yaml.py 29_json_test.json
9+
"""
10+
11+
# load json data
12+
json_data = json.loads(open(sys.argv[1]).read())
13+
# convert unicode to string
14+
converted_json_data = json.dumps(json_data)
15+
# output yaml
16+
print(yaml.dump(yaml.load(converted_json_data), default_flow_style=False))

readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
1. **02_find_all_links.py**: get all links from a webpage
55
1. **03_simple_twitter_manager.py**: accessing the Twitter API, example functions
66
1. **04_rename_with_slice.py**: rename group of files, within a single directory, using slice
7-
1. **05_load_json_without_dupes.py**: load json, convert to dict, raise error if there is a duplicate key
7+
1. **05_load_json_without_dupes.py**: load JSON, convert to dict, raise error if there is a duplicate key
88
1. **06_execution_time.py**: class used for timing execution of code
99
1. **07_benchmark_permissions_loading_django.py**: benchmark loading of permissions in Django
1010
1. **08_basic_email_web_crawler.py**: web crawler for grabbing emails from a website
@@ -27,4 +27,5 @@
2727
1. **25_ip2geolocation.py**: Given a CSV file with an ip address (see sample - *25_sample_csv.csv*), return the geolocation based on the ip.
2828
1. **26_stock_scraper.py**: Scrape the S&P 500 Companies list from Wikipedia, then output the data.
2929
1. **27_send_sms.py**: Send SMS message via [TextBelt](http://textbelt.com/)
30-
1. **28_income_tax_calculator.py**: Income tax calcuator via [Taxee](http://taxee.io/)
30+
1. **28_income_tax_calculator.py**: Income tax calculator via [Taxee](http://taxee.io/)
31+
1. **29_json_to_yaml.py**: Convert JSON to YAML

requirements.txt

Lines changed: 1 addition & 9 deletions

0 commit comments

Comments
 (0)