Last active
June 10, 2019 00:01
-
-
Save lalitkale/70f229ad9970c0382f8995e0613cd310 to your computer and use it in GitHub Desktop.
Json Flattening Python Code - My First Useful Solution in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! python | |
import shutil | |
import sys | |
import json | |
from flatten_json import flatten | |
# Author: Lalit kale | |
# Tested with python version 3.6.6 | |
# This is the program through which build engineers can transform appsettings.json file | |
# into Octopus Deploy tool's variables in the format required by my employer. | |
# How to Run the Program | |
# 1. Install Python | |
# 2. On Command Line execute following command without '' | |
# 3. 'pip install flatten_json' | |
# 4. On Command line execute 'py .\octovariables.py' | |
# from the same directory as that of python script and appsettings.json | |
input_file = 'appsettings.json' | |
output_file = 'ocotpus_variables.json' | |
seperator_char = '__' | |
with open(input_file) as json_file: | |
dataDict = json.load(json_file) | |
result = flatten(dataDict,seperator_char) | |
with open(output_file, 'w') as outfile: | |
json.dump(result, outfile) | |
outfile.close() | |
print("Octopus variables file generated successfully!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment