Merge pull request #316 from SiddheshKukade/master

Feature : JSON to YAML file Converter
This commit is contained in:
Advaita Saha 2022-10-10 20:46:38 +05:30 committed by GitHub
commit 3427da871d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 22 deletions

View File

@ -238,13 +238,28 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
<sub><b>YUNGH OG</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/SiddheshKukade">
<img src="https://avatars.githubusercontent.com/u/65951872?v=4" width="100;" alt="SiddheshKukade"/>
<br />
<sub><b>Siddhesh Bhupendra Kuakde</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/varunKT001">
<img src="https://avatars.githubusercontent.com/u/83509023?v=4" width="100;" alt="varunKT001"/>
<br />
<sub><b>Varun Tiwari</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/avyayjain">
<img src="https://avatars.githubusercontent.com/u/63355322?v=4" width="100;" alt="avyayjain"/>
<br />
<sub><b>Avyay Jain</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/drk1rd">
<img src="https://avatars.githubusercontent.com/u/58465650?v=4" width="100;" alt="drk1rd"/>
@ -258,8 +273,7 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
<br />
<sub><b>Null</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/rohitgarud21">
<img src="https://avatars.githubusercontent.com/u/115347445?v=4" width="100;" alt="rohitgarud21"/>
@ -287,7 +301,8 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
<br />
<sub><b>Srinjoy Pati</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/Shradha-Suman">
<img src="https://avatars.githubusercontent.com/u/103067896?v=4" width="100;" alt="Shradha-Suman"/>
@ -301,8 +316,7 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
<br />
<sub><b>Nishant Pacharne</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/thegeekyb0y">
<img src="https://avatars.githubusercontent.com/u/84658112?v=4" width="100;" alt="thegeekyb0y"/>
@ -330,7 +344,8 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
<br />
<sub><b>Mayuri Kolhe</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/parinzee">
<img src="https://avatars.githubusercontent.com/u/30139280?v=4" width="100;" alt="parinzee"/>
@ -344,21 +359,6 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
<br />
<sub><b>Sayan Roy</b></sub>
</a>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/SiddheshKukade">
<img src="https://avatars.githubusercontent.com/u/65951872?v=4" width="100;" alt="SiddheshKukade"/>
<br />
<sub><b>Siddhesh Bhupendra Kuakde</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/varunKT001">
<img src="https://avatars.githubusercontent.com/u/83509023?v=4" width="100;" alt="varunKT001"/>
<br />
<sub><b>Varun Tiwari</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ambushneupane">

View File

@ -0,0 +1,4 @@
### JSON to YAML file converter
Takes JSON data and converts it into YAML file by braking the JSON array and using the YAML library of python
### To Execute the code
`json2yaml.py input_file.json output_file.yaml`

View File

@ -0,0 +1,35 @@
import json
import os
import sys
import yaml
# Checking there is a file name passed
if len(sys.argv) > 1:
# Opening the file
if os.path.exists(sys.argv[1]):
source_file = open(sys.argv[1], "r")
source_content = json.load(source_file)
source_file.close()
# Failikng if the file isn't found
else:
print("ERROR: " + sys.argv[1] + " not found")
exit(1)
# No file, no usage
else:
print("Usage: json2yaml.py <source_file.json> [target_file.yaml]")
# Processing the conversion
output = yaml.dump(source_content)
# If no target file send to stdout
if len(sys.argv) < 3:
print(output)
# If the target file already exists exit
elif os.path.exists(sys.argv[2]):
print("ERROR: " + sys.argv[2] + " already exists")
exit(1)
# Otherwise write to the specified file
else:
target_file = open(sys.argv[2], "w")
target_file.write(output)
target_file.close()