{"id":20492057,"url":"https://github.com/zotonic/jsxrecord","last_synced_at":"2025-04-13T17:01:52.565Z","repository":{"id":55477722,"uuid":"133832245","full_name":"zotonic/jsxrecord","owner":"zotonic","description":"JSON encoding with records and 'null'/'undefined' mapping for Erlang","archived":false,"fork":false,"pushed_at":"2024-09-09T08:09:15.000Z","size":1118,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-10T07:44:16.860Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zotonic.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-05-17T15:20:54.000Z","updated_at":"2024-09-09T06:13:06.000Z","dependencies_parsed_at":"2023-10-15T18:04:33.464Z","dependency_job_id":"ebb64b84-b2d0-4612-8581-9be31184de86","html_url":"https://github.com/zotonic/jsxrecord","commit_stats":{"total_commits":17,"total_committers":2,"mean_commits":8.5,"dds":0.3529411764705882,"last_synced_commit":"d5fe8c65ca715302c2876e87534e00bdd48068d3"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotonic%2Fjsxrecord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotonic%2Fjsxrecord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotonic%2Fjsxrecord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotonic%2Fjsxrecord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zotonic","download_url":"https://codeload.github.com/zotonic/jsxrecord/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224819030,"owners_count":17375203,"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":[],"created_at":"2024-11-15T17:27:26.302Z","updated_at":"2024-11-15T17:27:27.062Z","avatar_url":"https://github.com/zotonic.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Test](https://github.com/zotonic/jsxrecord/workflows/Test/badge.svg)\n\n# JSON encoding with records and 'null'/'undefined' mapping\n\nOriginally, this was a wrapper around `jsx` to handle encoding and decoding of Erlang records, but [euneus](https://github.com/williamthome/euneus) gives to\njsxrecord a better performance.\n\n## JSON null handling\n\nTo ease the interop between Erlang and JSON the 'null' handling is changed:\n\n    Erlang    -\u003e    JSON     -\u003e     Erlang\n\n    undefined       null            undefined\n    null            null            undefined\n\n\n## How to use\n\nBefore records can be encoded or decoded the record definitions need to be loaded.\n\nAfter the definitions are loaded then all encoding/decoding is done transparently.\n\n### Loading record definitions\n\nThe record definitions are loaded from modules and compiled into a runtime loaded module\ncontaining all field names and default values.\n\nTo add record definitions from `mymodule`\n\n    ok = jsxrecord:load_records( [ mymodule ]).\n\nTo see the current record definitions:\n\n    jsxrecord:record_defs()\n\nThis returns a map with all known record definitions.\n\n### Encoding/decoding records\n\nLet's assume the following record definition has been loaded:\n\n    -record(test, { a = 1, b = 2, c }).\n\nThis can now be encoded with:\n\n    jsxrecord:encode( #test{} ).\n\nThe resulting JSON is:\n\n    {\"_record\":\"test\",\"a\":1,\"b\":2,\"c\":null}\n\nDecoding returns the `#test{}`:\n\n    #test{} = jsxrecord:decode(\u003c\u003c\"{\\\"_record\\\":\\\"test\\\",\\\"a\\\":1,\\\"b\\\":2,\\\"c\\\":null}\"\u003e\u003e).\n\nDefaults are automatically added for fields missing in the JSON:\n\n    #test{ a = 1, b = 2, c = undefined } = jsxrecord:decode(\u003c\u003c\"{\\\"_record\\\":\\\"test\\\"}\"\u003e\u003e).\n\n### Encoding and decoding datetime and timestamp tuples\n\nDatetime tuples are assumed to be in UTC, and are converted into an ISO8601 string:\n\n    \u003c\u003c\"\\\"2008-12-10T13:30:00Z\\\"\"\u003e\u003e = jsxrecord:encode({{2008, 12, 10}, {13, 30, 0}})\n\nThey are converted back into a datetime tuple:\n\n    {{2008, 12, 10}, {13, 30, 0}} = jsxrecord:decode(\u003c\u003c\"\\\"2008-12-10T13:30:00Z\\\"\"\u003e\u003e)\n\nErlang timestamp tuples are also converted into an ISO8601 string, but with added precision:\n\n    \u003c\u003c\"\\\"2020-06-12T14:00:11.571Z\\\"\"\u003e\u003e = jsxrecord:encode({1591,970411,571321})\n\nA little bit of precision is lost when converting it back to a timestamp tuple:\n\n    {1591,970411,571000} = jsxrecord:decode(\u003c\u003c\"\\\"2020-06-12T14:00:11.571Z\\\"\"\u003e\u003e)\n\n\n## Configuration\n\nSet the application env `jsxrecord.record_modules` to a list of modules whose records need to\nbe loaded on first use of the encoder or decoder.\n\n\n## Performance\n\nThe input of encode and the output of decode are parsed and expanded.\nThis makes the encoder and decoder slower than pure `jsx`.\nThough the difference shouldn't be too bad in normal usage.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzotonic%2Fjsxrecord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzotonic%2Fjsxrecord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzotonic%2Fjsxrecord/lists"}