Skip to content

Conversation

@tommcd
Copy link

@tommcd tommcd commented May 29, 2024

I want to keep indentation inside code blocks to allow use cases such as creating file content with significant whitespace:

cat << EOF > format_json.py
#!/usr/bin/env python3
import sys
import json

def main():
    input_data = sys.stdin.read()

    try:
        parsed_data = json.loads(input_data)
    except json.JSONDecodeError:
        print("Error: Input is not valid JSON", file=sys.stderr)
        sys.exit(1)

    json.dump(parsed_data, sys.stdout, indent=4)

if __name__ == "__main__":
    main()
EOF

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant