Spaces:
Paused
Paused
Download scripts/jsonl_to_json.py from tareek/honcho-api: direct link, hf CLI and curl.
- Browser
- Download file 697 Bytes
-
https://huggingface.co/spaces/tareek/honcho-api/resolve/main/scripts/jsonl_to_json.py
- Command line
-
hf download hf://spaces/tareek/honcho-api/scripts/jsonl_to_json.py
-
curl -L -o jsonl_to_json.py https://huggingface.co/spaces/tareek/honcho-api/resolve/main/scripts/jsonl_to_json.py
697 Bytes
| #!/usr/bin/env python3 | |
| """Convert a JSONL file to a JSON array.""" | |
| import json | |
| import sys | |
| def main() -> None: | |
| """Parse command-line arguments and convert JSONL file to JSON array. | |
| Reads a JSONL file where each line is a valid JSON object, aggregates | |
| all records into a list, and outputs as a formatted JSON array to stdout. | |
| Exits with code 1 if arguments are invalid. | |
| """ | |
| if len(sys.argv) != 2: | |
| print(f"Usage: {sys.argv[0]} <input.jsonl>", file=sys.stderr) | |
| sys.exit(1) | |
| with open(sys.argv[1]) as f: | |
| records = [json.loads(line) for line in f if line.strip()] | |
| print(json.dumps(records, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |