index.sxml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. (html (@ (xmlns "http://www.w3.org/1999/xhtml")
  2. (xml:lang "en"))
  3. (head
  4. (title "JSON Parser")
  5. (style (@ (type "text/css"))
  6. "
  7. body {
  8. color: #000000;
  9. background-color: #d6e6e6;
  10. margin-top: 1cm;
  11. margin-left: 1cm;
  12. line-height: 1.6;
  13. font-family: sans-serif;
  14. }
  15. h1, h2 {
  16. color: #004646;
  17. }
  18. "))
  19. (body
  20. (h1 "JSON Parser")
  21. (h2 "(import (macduffie json))")
  22. (p
  23. "(macduffie json) is just a simple JSON parser. This library
  24. is now based on the "
  25. (a (@ (href "https://github.com/fourthbit/spheres"))
  26. "SchemeSpheres") " JSON parser, and no longer has any code from
  27. Dominique Boucher. With this change, the license is now Expat
  28. (MIT). Furthermore, the parser looks close to standards
  29. compliant, but there remains a problem with Unicode surrogate
  30. pairs.")
  31. (p
  32. "This library depends on (srfi 69) to represent JSON objects.
  33. Otherwise, only scheme-small libraries are used.")
  34. (p
  35. "This library is regularly tested in Chibi, Kawa, and Gauche (in
  36. R7RS-strict mode).")
  37. (h2 "Library Procedures")
  38. (ul (@ (style "list-style: none;"))
  39. (li (@ (style "margin-bottom: 20px;"))
  40. (b "(json-read [port])")
  41. " Reads a JSON file from " (i "port") " and converts it to
  42. Scheme data. " (i "port") " defaults to (current-input-port).")
  43. (li (@ (style "margin-bottom: 20px;"))
  44. (b "(json-write value [port])")
  45. " Converts " (i "value") " to a JSON file and writes it to "
  46. (i "port") ". " (i "port") " defaults to (current-output-port).")
  47. (li (@ (style "margin-bottom: 20px;"))
  48. (b "(json-read-string str)")
  49. " Reads a JSON string " (i "str") " and returns the corresponding
  50. Scheme data.")
  51. (li (@ (style "margin-bottom: 20px;"))
  52. (b "(json-read-file filepath)")
  53. " Reads a JSON file at " (i "filepath") " and returns the
  54. corresponding Scheme data.")
  55. (li (@ (style "margin-bottom: 20px;"))
  56. (b "(json-write-string value [prettify] [space-char space-count])")
  57. " Writes " (i "value") " to a new JSON string which is returned. "
  58. (i "prettify") " writes the JSON in pretty-printed form, and defaults
  59. to #f. " (i "space-char") " and " (i "space-count") " specify the
  60. indentation for pretty-printing, and default to #\\tab and 1.")
  61. (li (@ (style "margin-bottom: 20px;"))
  62. (b "(json-write-file value filepath [prettify] [space-char
  63. space-count])") " Writes " (i "value") " to a JSON file at "
  64. (i "filepath") ". The optional arguments are the same as
  65. json-write-string and have the same defaults.")
  66. (li (@ (style "margin-bottom: 20px;"))
  67. (b "(json-null)") " Returns a record of the type json-null, for which
  68. (eq? (json-null) (json-null)) always returns #t.")
  69. (li (@ (style "margin-bottom: 20px;"))
  70. (b "(json-null? v)") " Returns #t if " (i "v") " is a record of
  71. the type json-null."))
  72. (h2 "To do:")
  73. (ul
  74. (li
  75. "Correctly write Unicode surrogate pairs"))
  76. (h2 "Performance")
  77. (p
  78. "This library will not work well for very large files. According
  79. to my tests, here are the relative performance of Chibi, Kawa,
  80. and Gauche: ")
  81. (ul
  82. (li
  83. "Kawa was ok with a 1,000-line JSON file. Performance was
  84. unacceptable for a 5,000-line JSON file.")
  85. (li
  86. "Chibi was ok with a 5,000-line JSON file. Performance was
  87. unacceptable for a 10,000-line JSON file.")
  88. (li
  89. "Gauche was ok with a 100,000-line JSON file. Performance
  90. was unacceptable for a 500,000-line JSON file."))
  91. (h2 "Data types")
  92. (p
  93. "Note that keys are internally represented as symbols.")
  94. (table (@ (border "1")
  95. (style "width:400")
  96. (summary "Comparison of JSON vs Scheme data"))
  97. (tr
  98. (td (@ (width "200"))
  99. (b "Scheme"))
  100. (td (@ (width "200"))
  101. (b "JSON")))
  102. (tr
  103. (td "AList (with symbol keys)")
  104. (td "Object"))
  105. (tr
  106. (td "Vector")
  107. (td "Array"))
  108. (tr
  109. (td "String")
  110. (td "String"))
  111. (tr
  112. (td "Number")
  113. (td "Number"))
  114. (tr
  115. (td "#t")
  116. (td "true"))
  117. (tr
  118. (td "#f")
  119. (td "false"))
  120. (tr
  121. (td "json-null record type")
  122. (td "null")))))