Skip to content

Instantly share code, notes, and snippets.

@d10xa
Created January 25, 2019 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d10xa/df1ebf279a5041feebc80b954002c98d to your computer and use it in GitHub Desktop.
Save d10xa/df1ebf279a5041feebc80b954002c98d to your computer and use it in GitHub Desktop.
Wraps json from stdin into string field
import json, sys; print(json.dumps({sys.argv[1] if len(sys.argv) > 1 else 'data': json.dumps(json.loads(sys.stdin.read()), ensure_ascii=False)}, ensure_ascii=False))
@d10xa
Copy link
Author

d10xa commented Jan 25, 2019

wrap:

echo '{"hello":"world"}' | python jsoninjson.py | python jsoninjson.py | python jsoninjson.py
{"data": "{\"data\": \"{\\\"data\\\": \\\"{\\\\\\\"hello\\\\\\\": \\\\\\\"world\\\\\\\"}\\\"}\"}"}

expand:

echo '{"hello":"world"}' | python jsoninjson.py | python jsoninjson.py | python jsoninjson.py | jq .data -r | jq .data -r | jq .data -r
{"hello": "world"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment