You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.6 KiB

14 years ago
  1. Jiffy - JSON NIFs for Erlang
  2. ============================
  3. A JSON parser as a NIF. This is a complete rewrite of the work I did
  4. in EEP0018 that was based on Yajl. This new version is a hand crafted
  5. state machine that does its best to be as quick and efficient as
  6. possible while not placing any constraints on the parsed JSON.
  7. Usage
  8. -----
  9. Jiffy is a simple API. The only thing that might catch you off guard
  10. is that the return type of jiffy:encode/1 is an iolist even though it
  11. returns a binary most of the time.
  12. A quick note on unicode. Jiffy only understands utf-8 in binaries. End
  13. of story. Also, there is a jiffy:encode/2 that takes a list of options
  14. for encoding. Currently the only supported option is `uescape`.
  15. Errors are raised as exceptions.
  16. Eshell V5.8.2 (abort with ^G)
  17. 1> jiffy:decode(<<"{\"foo\": \"bar\"}">>).
  18. {[{<<"foo">>,<<"bar">>}]}
  19. 2> Doc = {[{foo, [<<"bing">>, 2.3, true]}]}.
  20. {[{foo,[<<"bing">>,2.3,true]}]}
  21. 3> jiffy:encode(Doc).
  22. <<"{\"foo\":[\"bing\",2.3,true]}">>
  23. Data Format
  24. -----------
  25. Erlang JSON Erlang
  26. ==========================================================================
  27. null -> null -> null
  28. true -> true -> true
  29. false -> false -> false
  30. "hi" -> [104, 105] -> [104, 105]
  31. <<"hi">> -> "hi" -> <<"hi">>
  32. hi -> "hi" -> <<"hi">>
  33. 1 -> 1 -> 1
  34. 1.25 -> 1.25 -> 1.25
  35. [] -> [] -> []
  36. [true, 1.0] -> [true, 1.0] -> [true, 1.0]
  37. {[]} -> {} -> {[]}
  38. {[{foo, bar}]} -> {"foo": "bar"} -> {[{<<"foo">>, <<"bar">>}]}
  39. {[{"foo", bar}]} -> {"foo": "bar"} -> {[{<<"foo">>, <<"bar">>}]}
  40. {[{"foo", "bar"}]} -> {"foo": [98,97,114]} -> {[{<<"foo">>, "bar"}]}
  41. {[{<<"foo">>, <<"bar">>}]} -> {"foo": "bar"} -> {[{<<"foo">>, <<"bar">>}]}
  42. Its important to note that while keys in objects can be an iolist(),
  43. values will always be treated as arrays of integeres regardless of
  44. whether Erlang displays them as a string.
  45. Improvements over EEP0018
  46. -------------------------
  47. Jiffy should be in all ways an improvemnt over EEP0018. It no longer
  48. imposes limits on the nesting depth. It is capable of encoding and
  49. decoding large numbers and it does quite a bit more checking for validity
  50. of valid UTF-8 in strings.