{"id":13562035,"url":"https://github.com/sile/jsone","last_synced_at":"2025-05-14T11:12:24.967Z","repository":{"id":10944574,"uuid":"13252781","full_name":"sile/jsone","owner":"sile","description":"Erlang JSON library","archived":false,"fork":false,"pushed_at":"2024-11-28T00:28:06.000Z","size":2810,"stargazers_count":292,"open_issues_count":4,"forks_count":72,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-04-12T04:44:05.282Z","etag":null,"topics":["erlang","json"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sile.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-10-01T19:03:06.000Z","updated_at":"2025-03-27T23:43:44.000Z","dependencies_parsed_at":"2024-01-14T03:45:03.430Z","dependency_job_id":"af72c74f-f674-443b-9320-e0b1901a5b6e","html_url":"https://github.com/sile/jsone","commit_stats":null,"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sile%2Fjsone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sile%2Fjsone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sile%2Fjsone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sile%2Fjsone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sile","download_url":"https://codeload.github.com/sile/jsone/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129525,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["erlang","json"],"created_at":"2024-08-01T13:01:03.848Z","updated_at":"2025-05-14T11:12:24.866Z","avatar_url":"https://github.com/sile.png","language":"Erlang","funding_links":[],"categories":["Libraries","Erlang"],"sub_categories":["JSON"],"readme":"jsone\n=====\n\n[![hex.pm version](https://img.shields.io/hexpm/v/jsone.svg)](https://hex.pm/packages/jsone)\n[![Build Status](https://github.com/sile/jsone/workflows/build/badge.svg)](https://github.com/sile/jsone)\n[![Code Coverage](https://codecov.io/gh/sile/jsone/branch/master/graph/badge.svg)](https://codecov.io/gh/sile/jsone/branch/master)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nAn Erlang library for encoding, decoding [JSON](http://json.org/index.html) data.\n\n\nFeatures\n--------\n- Provides simple encode/decode function only\n- [RFC7159](http://www.ietf.org/rfc/rfc7159.txt)-compliant\n- Supports UTF-8 encoded binary\n- Pure Erlang\n- Highly Efficient\n  - Maybe one of the fastest JSON library (except those which are implemented in NIF)\n      - See [Benchmark](benchmark/README.md)\n  - Decode function is written in continuation-passing style(CPS)\n      - CPS facilitates application of 'creation of sub binary delayed' optimization\n      - See also [Erlang Efficiency Guide](http://www.erlang.org/doc/efficiency_guide/binaryhandling.html)\n\n\nQuickStart\n----------\n\n```sh\n# clone\n$ git clone git://github.com/sile/jsone.git\n$ cd jsone\n\n# compile\n$ make compile\n\n# run tests\n$ make eunit\n\n# dialyze\n$ make dialyze\n\n# Erlang shell\n$ make start\n1\u003e jsone:decode(\u003c\u003c\"[1,2,3]\"\u003e\u003e).\n[1,2,3]\n```\n\nUsage Example\n-------------\n\n```erlang\n%% Decode\n\u003e jsone:decode(\u003c\u003c\"[1,2,3]\"\u003e\u003e).\n[1,2,3]\n\n\u003e jsone:decode(\u003c\u003c\"{\\\"1\\\":2}\"\u003e\u003e).\n#{\u003c\u003c\"1\"\u003e\u003e =\u003e 2}\n\n\u003e jsone:decode(\u003c\u003c\"{\\\"1\\\":2}\"\u003e\u003e, [{object_format, tuple}]). % tuple format\n{[{\u003c\u003c\"1\"\u003e\u003e, 2}]}\n\n\u003e jsone:decode(\u003c\u003c\"{\\\"1\\\":2}\"\u003e\u003e, [{object_format, proplist}]). % proplist format\n[{\u003c\u003c\"1\"\u003e\u003e, 2}]\n\n\u003e jsone:try_decode(\u003c\u003c\"[1,2,3] \\\"next value\\\"\"\u003e\u003e). % try_decode/1 returns remaining (unconsumed binary)\n{ok,[1,2,3],\u003c\u003c\" \\\"next value\\\"\"\u003e\u003e}\n\n% error: raises exception\n\u003e jsone:decode(\u003c\u003c\"1.x\"\u003e\u003e).\n** exception error: bad argument\n     in function  jsone_decode:number_fraction_part_rest/6\n        called as jsone_decode:number_fraction_part_rest(\u003c\u003c\"x\"\u003e\u003e,1,1,0,[],\u003c\u003c\u003e\u003e)\n     in call from jsone:decode/1 (src/jsone.erl, line 71)\n\n% error: returns {error, Reason}\n\u003e jsone:try_decode(\u003c\u003c\"1.x\"\u003e\u003e).\n{error,{badarg,[{jsone_decode,number_fraction_part_rest,\n                              [\u003c\u003c\"x\"\u003e\u003e,1,1,0,[],\u003c\u003c\u003e\u003e],\n                              [{line,228}]}]}}\n\n\n%% Encode\n\u003e jsone:encode([1,2,3]).\n\u003c\u003c\"[1,2,3]\"\u003e\u003e\n\n\u003e jsone:encode(#{\u003c\u003c\"key\"\u003e\u003e =\u003e \u003c\u003c\"value\"\u003e\u003e}).  % map format\n\u003e jsone:encode({[{\u003c\u003c\"key\"\u003e\u003e, \u003c\u003c\"value\"\u003e\u003e}]}). % tuple format\n\u003e jsone:encode([{\u003c\u003c\"key\"\u003e\u003e, \u003c\u003c\"value\"\u003e\u003e}]).  % proplist format\n\u003c\u003c\"{\\\"key\\\":\\\"value\\\"}\"\u003e\u003e\n\n\u003e jsone:encode(#{key =\u003e \u003c\u003c\"value\"\u003e\u003e}). % atom key is allowed\n\u003c\u003c\"{\\\"key\\\":\\\"value\\\"}\"\u003e\u003e\n\n% error: raises exception\n\u003e jsone:encode(#{123 =\u003e \u003c\u003c\"value\"\u003e\u003e}). % non binary|atom key is not allowed\n** exception error: bad argument\n     in function  jsone_encode:object_members/3\n        called as jsone_encode:object_members([{123,\u003c\u003c\"value\"\u003e\u003e}],[],\u003c\u003c\"{\"\u003e\u003e)\n     in call from jsone:encode/1 (src/jsone.erl, line 97)\n\n% error: returns {error, Reason}\n\u003e jsone:try_encode({[{123, \u003c\u003c\"value\"\u003e\u003e}]}).\n{error,{badarg,[{jsone_encode,object_members,\n                              [[{123,\u003c\u003c\"value\"\u003e\u003e}],[],\u003c\u003c\"{\"\u003e\u003e],\n                              [{line,138}]}]}}\n\n% 'object_key_type' option allows non-string object key\n\u003e jsone:encode({[{123, \u003c\u003c\"value\"\u003e\u003e}]}, [{object_key_type, scalar}]).\n\u003c\u003c\"{\\\"123\\\":\\\"value\\\"}\"\u003e\u003e\n\n% 'undefined_as_null' option allows encoding atom undefined as null\n\u003e jsone:encode(undefined,[undefined_as_null]).\n\u003c\u003c\"null\"\u003e\u003e\n\n%% Pretty Print\n\u003e Data = [true, #{\u003c\u003c\"1\"\u003e\u003e =\u003e 2, \u003c\u003c\"array\"\u003e\u003e =\u003e [[[[1]]], #{\u003c\u003c\"ab\"\u003e\u003e =\u003e \u003c\u003c\"cd\"\u003e\u003e}, [], #{}, false]}, null].\n\u003e io:format(\"~s\\n\", [jsone:encode(Data, [{indent, 2}, {space, 1}])]).\n[\n  true,\n  {\n    \"1\": 2,\n    \"array\": [\n      [\n        [\n          [\n            1\n          ]\n        ]\n      ],\n      {\n        \"ab\": \"cd\"\n      },\n      [],\n      {},\n      false\n    ]\n  },\n  null\n]\nok\n\n%% Number Format\n\u003e jsone:encode(1). % integer\n\u003c\u003c\"1\"\u003e\u003e\n\n\u003e jsone:encode(1.23). % float\n\u003c\u003c\"1.22999999999999998224e+00\"\u003e\u003e % default: scientific notation\n\n\u003e jsone:encode(1.23, [{float_format, [{decimals, 4}]}]). % decimal notation\n\u003c\u003c\"1.2300\"\u003e\u003e\n\n\u003e jsone:encode(1.23, [{float_format, [{decimals, 4}, compact]}]). % compact decimal notation\n\u003c\u003c\"1.23\"\u003e\u003e\n\n%% If you want to safely cast object keys to atoms, the `attempt_atom' option will help.\n\u003e jsone:decode(\u003c\u003c\"{\\\"hello\\\": \\\"world\\\"}\"\u003e\u003e, [{keys, attempt_atom}]).\n#{\u003c\u003c\"hello\"\u003e\u003e =\u003e \u003c\u003c\"world\"\u003e\u003e}  % There is no atom named \"hello\", so the key is decoded as binary.\n\n\u003e hello.  % Create \"hello\" atom.\nhello\n\n\u003e jsone:decode(\u003c\u003c\"{\\\"hello\\\": \\\"world\\\"}\"\u003e\u003e, [{keys, attempt_atom}]).\n#{hello =\u003e \u003c\u003c\"world\"\u003e\u003e} % Now, the key is decoded as atom.\n```\n\n\nData Mapping (Erlang \u003c=\u003e JSON)\n-------------------------------\n\n```\nErlang                  JSON             Erlang\n=================================================================================================\n\nnull                   -\u003e null                       -\u003e null\nundefined              -\u003e null                       -\u003e undefined                  % undefined_as_null\ntrue                   -\u003e true                       -\u003e true\nfalse                  -\u003e false                      -\u003e false\n\u003c\u003c\"abc\"\u003e\u003e              -\u003e \"abc\"                      -\u003e \u003c\u003c\"abc\"\u003e\u003e\nabc                    -\u003e \"abc\"                      -\u003e \u003c\u003c\"abc\"\u003e\u003e % non-special atom is regarded as a binary\n{{2010,1,1},{0,0,0}}   -\u003e \"2010-01-01T00:00:00Z\"     -\u003e \u003c\u003c\"2010-01-01T00:00:00Z\"\u003e\u003e     % datetime*\n{{2010,1,1},{0,0,0.0}} -\u003e \"2010-01-01T00:00:00.000Z\" -\u003e \u003c\u003c\"2010-01-01T00:00:00.000Z\"\u003e\u003e % datetime*\n123                    -\u003e 123                        -\u003e 123\n123.4                  -\u003e 123.4                      -\u003e 123.4\n[1,2,3]                -\u003e [1,2,3]                    -\u003e [1,2,3]\n{[]}                   -\u003e {}                         -\u003e {[]}                       % object_format=tuple\n{[{key, \u003c\u003c\"val\"\u003e\u003e}]}   -\u003e {\"key\":\"val\"}              -\u003e {[{\u003c\u003c\"key\"\u003e\u003e, \u003c\u003c\"val\"\u003e\u003e}]} % object_format=tuple\n[{}]                   -\u003e {}                         -\u003e [{}]                       % object_format=proplist\n[{\u003c\u003c\"key\"\u003e\u003e, val}]     -\u003e {\"key\":\"val\"}              -\u003e [{\u003c\u003c\"key\"\u003e\u003e, \u003c\u003c\"val\"\u003e\u003e}]   % object_format=proplist\n#{}                    -\u003e {}                         -\u003e #{}                        % object_format=map\n#{key =\u003e val}          -\u003e {\"key\":\"val\"}              -\u003e #{\u003c\u003c\"key\"\u003e\u003e =\u003e \u003c\u003c\"val\"\u003e\u003e}  % object_format=map\n{{json, IOList}}       -\u003e Value                      -\u003e ~~~                        % UTF-8 encoded term**\n{{json_utf8, Chars}}   -\u003e Value                      -\u003e ~~~                        % Unicode code points**\n```\n\n\\* see [jsone:datetime_encode_format()](doc/jsone.md#type-datetime_encode_format)\n\n\\** `{json, IOList}` and `{json_utf8, Chars}` allows inline already encoded JSON\nvalues. For example, you obtain JSON encoded data from database so you don't\nhave to decode it first and encode again. See [jsone:json_term()](doc/jsone.md#type-json_term).\n\nAPI\n---\n\nSee [EDoc Document](doc/jsone.md)\n\n\nBenchmark\n---------\n\nThe results of [poison](https://github.com/devinus/poison) benchmarking.\n\nSee the [benchmark/README.md](benchmark/README.md) file for more information.\n\n### Encoding (Unit: IPS=inputs per second)\n\n| Input data \\ Library | Jason      | jiffy       | JSON*  | jsone      | JSX    | Poison | Tiny   |\n|----------------------|-----------:|------------:|-------:|-----------:|-------:|-------:|-------:|\n| [Blockchain]         |     2.77 K |  **4.55 K** | 0.45 K | 1.44 K (3) | 0.60 K | 1.30 K | 0.99 K |\n| [Giphy]              |     230.65 |  **487.67** |  47.73 | 114.57 (4) |  44.97 | 114.57 | 113.59 |\n| [GitHub]             |     880.03 | **1566.67** | 139.79 | 300.26 (5) |  99.68 | 424.75 | 455.07 |\n| [GovTrack]           |       6.57 |   **24.92** |   2.33 |   5.35 (5) |   2.65 |   7.06 |   7.86 |\n| [Issue 90]           |  **22.80** |       21.92 |   0.77 |  14.30 (3) |   5.33 |  12.60 |  12.95 |\n| [JSON Generateor]    |     200.40 |  **606.81** |  42.45 | 147.12 (4) |  68.73 | 187.95 | 123.93 |\n| [Pokedex]            |     209.51 |  **776.67** |  62.60 | 161.45 (4) |  69.87 | 190.93 | 125.16 |\n| [UTF-8 unescaped]    |     626.25 | **6644.53** |1167.89 | 582.41 (4) | 273.48 | 401.44 | 220.14 |\n\n\\* Only `JSON` didn't escape non-ASCII unicode characters on the encoding\n\n[Blockchain]: https://github.com/devinus/poison/blob/4.0.1/bench/data/blockchain.json\n[Giphy]: https://github.com/devinus/poison/blob/4.0.1/bench/data/giphy.json\n[GitHub]: https://github.com/devinus/poison/blob/4.0.1/bench/data/github.json\n[GovTrack]: https://github.com/devinus/poison/blob/4.0.1/bench/data/govtrack.json\n[Issue 90]: https://github.com/devinus/poison/blob/4.0.1/bench/data/issue-90.json\n[JSON Generateor]: https://github.com/devinus/poison/blob/4.0.1/bench/data/json-generator.json\n[JSON Generateor (Pretty)]: https://github.com/devinus/poison/blob/4.0.1/bench/data/json-generator-pretty.json\n[Pokedex]: https://github.com/devinus/poison/blob/4.0.1/bench/data/pokedex.json\n[UTF-8 escaped]: https://github.com/devinus/poison/blob/4.0.1/bench/data/utf-8-escaped.json\n[UTF-8 unescaped]: https://github.com/devinus/poison/blob/4.0.1/bench/data/utf-8-unescaped.json\n\n### Decoding (Unit: IPS=inputs per second)\n\n| Input data \\ Library       | Jason      | jiffy       | JSON   | jsone      | JSX    | Poison | Tiny   |\n|----------------------------|-----------:|------------:|-------:|-----------:|-------:|-------:|-------:|\n| [Blockchain]               | **2.75 K** |      2.62 K | 0.35 K | 2.21 K (3) | 0.89 K | 1.32 K | 1.49 K |\n| [Giphy]                    |     212.18 |  **243.45** |  35.67 | 109.11 (5) |  64.32 | 110.76 | 114.54 |\n| [GitHub]                   |     973.41 | **1052.94** | 137.02 | 662.39 (3) | 271.97 | 438.79 | 542.67 |\n| [GovTrack]                 |  **10.77** |        8.32 |   0.80 |   5.08 (3) |   2.81 |   3.58 |   3.65 |\n| [Issue 90]                 |      17.85 |   **41.16** |   0.88 |  10.79 (5) |   6.02 |  13.63 |  14.03 |\n| [JSON Generateor]          | **320.79** |      243.93 |  25.16 | 184.23 (3) | 111.24 | 135.47 | 139.78 |\n| [JSON Generateor (Pretty)] | **273.57** |      205.09 |  25.04 | 158.82 (3) |  97.93 | 123.31 | 136.65 |\n| [Pokedex]                  | **527.63** |      285.43 |  33.70 | 245.36 (3) | 140.90 | 172.45 | 152.59 |\n| [UTF-8 escaped]            |    1224.48 | **7923.08** | 326.43 | 573.70 (4) | 550.36 | 918.21 | 520.31 |\n| [UTF-8 unescaped]          |     5.56 K | **12.54 K** | 1.35 K | 5.09 K (3) | 3.30 K | 4.39 K | 1.46 K |\n\n\nLicense\n-------\n\nThis library is released under the MIT License.\n\nSee the [COPYING](COPYING) file for full license information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsile%2Fjsone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsile%2Fjsone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsile%2Fjsone/lists"}