j2y and y2j filter programs, which convert streams of values between JSON and YAML - good for use with jq :)

This commit is contained in:
Danielle McLean 2016-10-27 11:25:29 +11:00
parent dd820bf691
commit 0dea194992
No known key found for this signature in database
GPG key ID: CC91589719027E94
2 changed files with 105 additions and 0 deletions

17
local/bin/y2j Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env python3
try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader
import sys, json
files = sys.argv[1:] or ('-',)
stdinUsed = False
for f in files:
if f == '-':
if stdinUsed: continue
stdinUsed = True
with open(f) if f != '-' else sys.stdin as stream:
l = SafeLoader(stream)
while l.check_data(): print(json.dumps(l.get_data()))