Skip to content

Commit 24d6113

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

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

29_json_test.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"colorsArray":[{
3+
"colorName":"red",
4+
"hexValue":"#f00"
5+
},
6+
{
7+
"colorName":"green",
8+
"hexValue":"#0f0"
9+
},
10+
{
11+
"colorName":"blue",
12+
"hexValue":"#00f"
13+
},
14+
{
15+
"colorName":"cyan",
16+
"hexValue":"#0ff"
17+
},
18+
{
19+
"colorName":"magenta",
20+
"hexValue":"#f0f"
21+
},
22+
{
23+
"colorName":"yellow",
24+
"hexValue":"#ff0"
25+
},
26+
{
27+
"colorName":"black",
28+
"hexValue":"#000"
29+
}
30+
]
31+
}

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
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
Flask==0.10.1
2-
Jinja2==2.7.3
3-
MarkupSafe==0.23
4-
Wand==0.4.0
5-
Werkzeug==0.10.4
6-
hurry.filesize==0.9
7-
itsdangerous==0.24
8-
lxml==3.4.4
9-
numpy==1.9.2
1+
PyYAML==3.11
102
requests==2.7.0
113
wheel==0.24.0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy