{"id":13508432,"url":"https://github.com/michalmuskala/jason","last_synced_at":"2025-05-13T21:04:18.626Z","repository":{"id":21592924,"uuid":"93335118","full_name":"michalmuskala/jason","owner":"michalmuskala","description":"A blazing fast JSON parser and generator in pure Elixir.","archived":false,"fork":false,"pushed_at":"2024-09-10T15:11:27.000Z","size":3710,"stargazers_count":1642,"open_issues_count":20,"forks_count":173,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-28T11:57:09.550Z","etag":null,"topics":["elixir","json"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michalmuskala.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2017-06-04T19:00:57.000Z","updated_at":"2025-04-24T16:02:28.000Z","dependencies_parsed_at":"2024-02-07T11:29:14.316Z","dependency_job_id":"5c3ea116-eb3b-44dd-8be1-d976d9c299a3","html_url":"https://github.com/michalmuskala/jason","commit_stats":{"total_commits":247,"total_committers":43,"mean_commits":5.744186046511628,"dds":0.2753036437246964,"last_synced_commit":"984bc078eb4b2084104751c7f1c5290b8338e06b"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michalmuskala%2Fjason","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michalmuskala%2Fjason/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michalmuskala%2Fjason/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michalmuskala%2Fjason/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michalmuskala","download_url":"https://codeload.github.com/michalmuskala/jason/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254028353,"owners_count":22002237,"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":["elixir","json"],"created_at":"2024-08-01T02:00:52.976Z","updated_at":"2025-05-13T21:04:18.602Z","avatar_url":"https://github.com/michalmuskala.png","language":"Elixir","funding_links":[],"categories":["JSON","Elixir"],"sub_categories":[],"readme":"# Jason [![Hex Version](https://img.shields.io/hexpm/v/jason.svg)](https://hex.pm/packages/jason) [![Hex Docs](https://img.shields.io/badge/docs-hexpm-blue.svg)](https://hexdocs.pm/jason/)\n\nA blazing fast JSON parser and generator in pure Elixir.\n\nThe parser and generator are at least twice as fast as other Elixir/Erlang libraries\n(most notably `Poison`).\nThe performance is comparable to `jiffy`, which is implemented in C as a NIF.\nJason is usually only twice as slow.\n\nBoth parser and generator fully conform to\n[RFC 8259](https://tools.ietf.org/html/rfc8259) and\n[ECMA 404](https://ecma-international.org/publications-and-standards/standards/ecma-404/)\nstandards. The parser is tested using [JSONTestSuite](https://github.com/nst/JSONTestSuite).\n\n## Installation\n\nThe package can be installed by adding `jason` to your list of dependencies\nin `mix.exs`:\n\n```elixir\ndef deps do\n  [{:jason, \"~\u003e 1.4\"}]\nend\n```\n\n## Basic Usage\n\n``` elixir\niex(1)\u003e Jason.encode!(%{\"age\" =\u003e 44, \"name\" =\u003e \"Steve Irwin\", \"nationality\" =\u003e \"Australian\"})\n\"{\\\"age\\\":44,\\\"name\\\":\\\"Steve Irwin\\\",\\\"nationality\\\":\\\"Australian\\\"}\"\n\niex(2)\u003e Jason.decode!(~s({\"age\":44,\"name\":\"Steve Irwin\",\"nationality\":\"Australian\"}))\n%{\"age\" =\u003e 44, \"name\" =\u003e \"Steve Irwin\", \"nationality\" =\u003e \"Australian\"}\n```\n\nFull documentation can be found at [https://hexdocs.pm/jason](https://hexdocs.pm/jason).\n\n## Use with other libraries\n\n### Postgrex\n\nVersions starting at 0.14.0 use `Jason` by default. For earlier versions, please refer to\n[previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#postgrex).\n\n### Ecto\n\nVersions starting at 3.0.0 use `Jason` by default. For earlier versions, please refer to\n[previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#ecto).\n\n### Plug (and Phoenix)\n\nPhoenix starting at 1.4.0 uses `Jason` by default. For earlier versions, please refer to\n[previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#plug-and-phoenix).\n\n### Absinthe\n\nYou need to pass the `:json_codec` option to `Absinthe.Plug`\n\n```elixir\n# When called directly:\nplug Absinthe.Plug,\n  schema: MyApp.Schema,\n  json_codec: Jason\n\n# When used in phoenix router:\nforward \"/api\",\n  to: Absinthe.Plug,\n  init_opts: [schema: MyApp.Schema, json_codec: Jason]\n```\n\n## Benchmarks\n\nDetailed benchmarks (including memory measurements):\nhttps://gist.github.com/michalmuskala/4d64a5a7696ca84ac7c169a0206640d5\n\nHTML reports for the benchmark (only performance measurements):\nhttp://michal.muskala.eu/jason/decode.html and http://michal.muskala.eu/jason/encode.html\n\n### Running\n\nBenchmarks against most popular Elixir \u0026 Erlang json libraries can be executed after\ngoing into the `bench/` folder and then executing `mix bench.encode` and `mix bench.decode`.\nA HTML report of the benchmarks (after their execution) can be found in\n`bench/output/encode.html` and `bench/output/decode.html` respectively.\n\n## Differences to Poison\n\nJason has a couple feature differences compared to Poison.\n\n  * Jason follows the JSON spec more strictly, for example it does not allow\n    unescaped newline characters in JSON strings - e.g. `\"\\\"\\n\\\"\"` will\n    produce a decoding error.\n  * no support for decoding into data structures (the `as:` option).\n  * no built-in encoders for `MapSet`, `Range` and `Stream`.\n  * no support for encoding arbitrary structs - explicit implementation\n    of the `Jason.Encoder` protocol is always required.\n  * different pretty-printing customisation options (default `pretty: true` works the same)\n\n### Encoders\n\nIf you require encoders for any of the unsupported collection types, I suggest\nadding the needed implementations directly to your project:\n\n```elixir\ndefimpl Jason.Encoder, for: [MapSet, Range, Stream] do\n  def encode(struct, opts) do\n    Jason.Encode.list(Enum.to_list(struct), opts)\n  end\nend\n```\n\nIf you need to encode some struct that does not implement the protocol,\nif you own the struct, you can derive the implementation specifying\nwhich fields should be encoded to JSON:\n\n```elixir\n@derive {Jason.Encoder, only: [....]}\ndefstruct # ...\n```\n\nIt is also possible to encode all fields, although this should be\nused carefully to avoid accidentally leaking private information\nwhen new fields are added:\n\n```elixir\n@derive Jason.Encoder\ndefstruct # ...\n```\n\nFinally, if you don't own the struct you want to encode to JSON,\nyou may use `Protocol.derive/3` placed outside of any module:\n\n```elixir\nProtocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])\nProtocol.derive(Jason.Encoder, NameOfTheStruct)\n```\n\n## Injecting an already encoded JSON inside a to-be-encoded structure\n\nIf parts of the to-be-encoded structure are already JSON-encoded, you can\nuse `Jason.Fragment` to mark the parts as already encoded, and avoid a\ndecoding/encoding roundtrip.\n\n```elixir\nalready_encoded_json = Jason.encode!(%{hello: \"world\"})\nJason.encode!(%{foo: Jason.Fragment.new(already_encoded_json)})\n```\n\nThis feature is especially useful if you need to cache a part of the JSON,\nor if it is already provided by another system (e.g. `jsonb_agg` with Postgres).\n\n## License\n\nJason is released under the Apache License 2.0 - see the [LICENSE](LICENSE) file.\n\nSome elements of tests and benchmarks have their origins in the\n[Poison library](https://github.com/devinus/poison) and were initially licensed under [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichalmuskala%2Fjason","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichalmuskala%2Fjason","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichalmuskala%2Fjason/lists"}