{"id":20776801,"url":"https://github.com/avocode/json-immutable","last_synced_at":"2025-04-30T18:11:12.080Z","repository":{"id":48257065,"uuid":"66721753","full_name":"avocode/json-immutable","owner":"avocode","description":"Immutable.JS structure-aware JSON serializer/deserializer","archived":false,"fork":false,"pushed_at":"2022-12-06T19:49:32.000Z","size":322,"stargazers_count":23,"open_issues_count":12,"forks_count":14,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-24T02:05:06.683Z","etag":null,"topics":["immutable","immutablejs","json"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/avocode.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}},"created_at":"2016-08-27T15:38:37.000Z","updated_at":"2021-11-08T05:11:49.000Z","dependencies_parsed_at":"2023-01-23T15:00:07.761Z","dependency_job_id":null,"html_url":"https://github.com/avocode/json-immutable","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avocode%2Fjson-immutable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avocode%2Fjson-immutable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avocode%2Fjson-immutable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avocode%2Fjson-immutable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avocode","download_url":"https://codeload.github.com/avocode/json-immutable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251758170,"owners_count":21638989,"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":["immutable","immutablejs","json"],"created_at":"2024-11-17T13:11:55.360Z","updated_at":"2025-04-30T18:11:12.059Z","avatar_url":"https://github.com/avocode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonImmutable\n\n[![Build Status](https://travis-ci.org/avocode/json-immutable.svg)](https://travis-ci.org/avocode/json-immutable)\n\nImmutable.JS structure-aware JSON serializer/deserializer built around the native `JSON` API.\n\n## Motivation\n\nBy using the native `JSON` API, Immutable.JS structures are serialized as plain objects and arrays with no type information. The goal was to preserve both Immutable.JS `Iterable` types (maps, lists, etc.) and `Record` types. `immutable.Map` supports and preserves key types while plain JavaScript object keys are coerced to strings. These types should also preserved.\n\n## Usage\n\n### Plain Objects and Primitive Types\n\n```javascript\nconst data = { 'a': 'b', 'c': 123, 'd': true }\n\n// Serialize\nconst json = serialize(data)\n// json == '{\"a\":\"b\",\"c\":123,\"d\":true}'\n\n// Deserialize\nconst result = deserialize(json)\n```\n\n### Native Object Types\n\n```javascript\nconst data = { 'created_at': new Date('2016-09-08'), 'pattern': /iamnative/g }\n\n// Serialize\nconst json = serialize(data)\n// json == '{\"created_at\":{\"__date\":\"2016-09-08T00:00:00Z\"},\"pattern\":{\"__regexp\":\"/iamnative/g\"}}'\n\n// Deserialize\nconst result = deserialize(json)\n```\n\n### Immutable Records\n\n```javascript\nconst SampleRecord = immutable.Record(\n  { 'a': 3, 'b': 4 },\n  'SampleRecord'\n)\n\nconst data = {\n  'x': SampleRecord({ 'a': 5 }),\n}\n\n// Serialize\nconst json = serialize(data)\n// json == '{\"x\":{\"__record\":\"SampleRecord\",\"data\":{\"a\":5}}}'\n\n// Deserialize\nconst result = deserialize(json, {\n  recordTypes: {\n    'SampleRecord': SampleRecord\n  }\n})\n```\n\nRecord types can be named. This is utilized by the serializer/deserializer to revive `immutable.Record` objects. See the `SampleRecord` name passed into `immutable.Record()` as the second argument.\n\nNOTE: When an unknown record type is encountered during deserialization, an error is thrown.\n\n### General Immutable Structures\n\n```javascript\nconst data = {\n  'x': immutable.Map({\n    'y': immutable.List.of(1, 2, 3)\n  }),\n}\n\n// Serialization\nconst json = serialize(data)\n// json == '{\"x\":{\"__iterable\":\"Map\",\"data\":[[\"y\",{\"__iterable\":\"List\",\"data\":[1,2,3]\"}]]}}'\n\n// Deserialize\nconst result = deserialize(json)\n```\n\n- Immutable structures, plain objects and primitive data can be safely composed together.\n\n- `immutable.Map` key type information is preserved as opposed to the bare `JSON` API.\n\nNOTE: When an unknown Immutable iterable type is encountered during deserialization, an error is thrown. The supported types are `List`, `Map`, `OrderedMap`, `Set`, `OrderedSet` and `Stack`.\n\n## API\n\n- **`serialize()`**\n\n    Arguments:\n\n    - `data`: The data to serialize.\n    - `options={}`: Serialization options.\n        - `pretty=false`: Whether to pretty-print the result (2 spaces).\n\n    Return value:\n\n    - `string`: The JSON representation of the input (`data`).\n\n- **`deserialize()`**\n\n    Arguments:\n\n    - `json`: A JSON representation of data.\n    - `options={}`: Deserialization options.\n        - `recordTypes={}`: `immutable.Record` factories.\n\n    Return value:\n\n    - `any`: Deserialized data.\n\n### Streaming API\n\n- **`createSerializationStream()`**\n\n    Arguments:\n\n    - `data`: The data to serialize.\n    - `options={}`: Serialization options.\n        - `pretty=false`: Whether to pretty-print the result (2 spaces).\n        - `bigChunks=false`: Whether the serialized data should only be split into chunks based on the reader speed. By default, each data structure level is processed in its own event loop microtask which.\n            - NOTE: When `bigChunks=true`, a (possibly substantial) portion of the data is serialized synchronously.\n\n    Return value:\n\n    - `stream.PassThrough\u003c!Buffer\u003e`: A readable stream emitting the JSON representation of the input (`data`).\n\n## Running Tests\n\n1. Clone the repository.\n2. `npm install`\n3. `npm test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favocode%2Fjson-immutable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favocode%2Fjson-immutable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favocode%2Fjson-immutable/lists"}