{"library":"jsonlines","code":"import jsonlines\nimport io\nimport os\n\n# Create a dummy file for demonstration\noutput_file = \"example_data.jsonl\"\ndata_to_write = [\n    {\"id\": 1, \"name\": \"Alice\", \"email\": \"alice@example.com\"},\n    {\"id\": 2, \"name\": \"Bob\", \"email\": \"bob@example.com\", \"status\": \"active\"},\n    {\"id\": 3, \"name\": \"Charlie\", \"data\": {\"city\": \"New York\", \"zip\": \"10001\"}}\n]\n\n# Writing JSON Lines data using the convenience 'open' function\nwith jsonlines.open(output_file, mode='w') as writer:\n    writer.write_all(data_to_write)\nprint(f\"Wrote {len(data_to_write)} records to {output_file}\")\n\n# Reading JSON Lines data\nprint(\"\\nReading records:\")\nread_records = []\nwith jsonlines.open(output_file) as reader:\n    for obj in reader:\n        read_records.append(obj)\n        print(obj)\n\nprint(f\"Total records read: {len(read_records)}\")\nassert read_records == data_to_write\n\n# Example of writing to an in-memory buffer using Writer class\nbuffer = io.StringIO()\nwith jsonlines.Writer(buffer) as writer:\n    writer.write({\"log_event\": \"started\", \"timestamp\": \"2023-01-01T12:00:00Z\"})\n    writer.write({\"log_event\": \"processed\", \"item_id\": 123})\n\nbuffer.seek(0) # Reset buffer position to read\nprint(\"\\nReading from in-memory buffer:\")\nwith jsonlines.Reader(buffer) as reader:\n    for log_entry in reader:\n        print(log_entry)\n\n# Clean up the dummy file\nos.remove(output_file)\nprint(f\"\\nCleaned up {output_file}\")","lang":"python","description":"The quickstart demonstrates writing and reading JSON Lines data using `jsonlines.open()` for file paths and the `jsonlines.Writer`/`jsonlines.Reader` classes for file-like objects (like `io.StringIO`). It covers basic object serialization, deserialization, and the use of context managers for proper resource handling.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}