json.tool.scm 583 B

123456789101112131415161718192021
  1. ;; This is a program to pretty-print json, like python -m json.tool
  2. (import (scheme base)
  3. (scheme write)
  4. (scheme process-context)
  5. (macduffie json))
  6. (define (read-all)
  7. (let loop ((l '()))
  8. (define next-char (read-char))
  9. (if (eof-object? next-char)
  10. (list->string (reverse l))
  11. (loop (cons next-char l)))))
  12. (define (main-proc args)
  13. (if (null? args)
  14. (display (json-write-string (json-read-string (read-all)) #t #\space 4))
  15. (display (json-write-string (json-read-string (read-all)) #t))))
  16. (main-proc (cdr (command-line)))