mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 03:48:56 +00:00
- Add --json boolean flag that modifies output format to JSON
- Works with --print: outputs expression result as JSON
- Works with --eval: acts like --print but outputs JSON
- Supports capturing module exports for main modules (CommonJS/ESM)
- Uses jsonStringify for proper JSON serialization
- Handles all JavaScript types including promises, dates, objects, arrays
- Shows error messages for non-serializable types (BigInt, circular refs)
Test results:
bun --print '42' --json # outputs: 42
bun --print '({x: 1})' --json # outputs: {"x":1}
bun --eval '({x: 1})' --json # outputs: {"x":1}
bun --eval 'null' --json # outputs: null
bun --eval 'undefined' --json # outputs: (nothing)
Includes comprehensive tests covering all data types and edge cases.