Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F57000343
yaml2json.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
yaml2json.py
View Options
#!/usr/bin/env python3
# -------------------------------------------------------------
# Nasqueron - API
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Create a JSON document from a YAML datasource
# License: Trivial work, not eligible to copyright
# -------------------------------------------------------------
import
json
import
sys
import
yaml
# -------------------------------------------------------------
# Convert
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
to_json
(
source_path
,
key
=
None
):
with
open
(
source_path
)
as
fd
:
data
=
yaml
.
safe_load
(
fd
)
if
key
:
data
=
data
[
key
]
return
json
.
dumps
(
data
,
indent
=
4
)
# -------------------------------------------------------------
# Application entry point
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
run
(
source_path
,
key
=
None
):
print
(
to_json
(
source_path
,
key
))
if
__name__
==
"__main__"
:
argc
=
len
(
sys
.
argv
)
if
argc
<
2
:
print
(
f
"Usage: {sys.argv[0]} <YAML datasource> [key to take]"
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
run
(
*
sys
.
argv
[
1
:
3
])
File Metadata
Details
Attached
Mime Type
text/x-script.python
Expires
Sat, Nov 14, 19:24 (2 d, 21 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4251719
Default Alt Text
yaml2json.py (1 KB)
Attached To
Mode
rAPI Nasqueron API
Attached
Detach File
Event Timeline
Log In to Comment