{"id":15519560,"url":"https://github.com/pichillilorenzo/jackson-js","last_synced_at":"2025-04-13T06:42:03.286Z","repository":{"id":42271404,"uuid":"173655040","full_name":"pichillilorenzo/jackson-js","owner":"pichillilorenzo","description":"JavaScript object serialization and deserialization library using decorators. It supports also advanced Object concepts such as polymorphism, Object identity and cyclic objects.","archived":false,"fork":false,"pushed_at":"2023-01-07T17:51:42.000Z","size":3156,"stargazers_count":91,"open_issues_count":42,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-26T23:09:09.193Z","etag":null,"topics":["jackson-javascript","jackson-js","jackson-json","javascript","javascript-library","json","json-decoder","json-decorators","json-deserialization","json-encoder","json-parse","json-parser","json-serialization","json-stringifier","json-stringify"],"latest_commit_sha":null,"homepage":"https://pichillilorenzo.github.io/jackson-js/latest/index.html","language":"TypeScript","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/pichillilorenzo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"lorenzo_pichilli","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://www.paypal.me/LorenzoPichilli"]}},"created_at":"2019-03-04T01:50:02.000Z","updated_at":"2025-03-09T07:57:29.000Z","dependencies_parsed_at":"2023-02-07T19:17:01.741Z","dependency_job_id":null,"html_url":"https://github.com/pichillilorenzo/jackson-js","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pichillilorenzo%2Fjackson-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pichillilorenzo%2Fjackson-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pichillilorenzo%2Fjackson-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pichillilorenzo%2Fjackson-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pichillilorenzo","download_url":"https://codeload.github.com/pichillilorenzo/jackson-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675440,"owners_count":21143763,"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":["jackson-javascript","jackson-js","jackson-json","javascript","javascript-library","json","json-decoder","json-decorators","json-deserialization","json-encoder","json-parse","json-parser","json-serialization","json-stringifier","json-stringify"],"created_at":"2024-10-02T10:22:01.540Z","updated_at":"2025-04-13T06:42:03.265Z","avatar_url":"https://github.com/pichillilorenzo.png","language":"TypeScript","funding_links":["https://patreon.com/lorenzo_pichilli","https://www.paypal.me/LorenzoPichilli","https://www.patreon.com/bePatron?u=9269604"],"categories":[],"sub_categories":[],"readme":"# jackson-js\n\n[![npm downloads](https://img.shields.io/npm/dm/jackson-js.svg)](https://www.npmjs.com/package/jackson-js)\n[![jackson-js version](https://img.shields.io/npm/v/jackson-js.svg)](https://www.npmjs.com/package/jackson-js)\n[![Travis](https://img.shields.io/travis/pichillilorenzo/jackson-js.svg?branch=master)](https://travis-ci.org/pichillilorenzo/jackson-js)\n[![Coverage Status](https://coveralls.io/repos/github/pichillilorenzo/jackson-js/badge.svg?branch=master)](https://coveralls.io/github/pichillilorenzo/jackson-js?branch=master)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](/LICENSE)\n[![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/LorenzoPichilli)\n[![Donate to this project using Patreon](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/bePatron?u=9269604)\n\nAs the name implies, `jackson-js` is heavily inspired by the famous Java [FasterXML/jackson library](https://github.com/FasterXML/jackson).\n\nIt can be used on both **client** (browser) and **server** (Node.js) side.\n\n## Why this library? What's the difference between using this library instead of `JSON.parse` and `JSON.stringify`?\n\nFor simple cases, you don't need this library of course, you can just use `JSON.parse` and `JSON.stringify` to serialize/deserialize JSON.\n\nWith `jackson-js` , you can easily manipulate your JavaScript objects/values serialization/deserialization using decorators such as `@JsonProperty()`, `@JsonFormat()`, `@JsonIgnore()`, and more. However, this library uses `JSON.parse` and `JSON.stringify` under the hood.\n\nFurthermore: \n- it not only deserialize JSON text into a JavaScript object, it also converts it into an **instance of the class** specified in the `context` option (similar packages are: [class-transformer](https://github.com/typestack/class-transformer) and [TypedJSON](https://github.com/JohnWeisz/TypedJSON)); instead, with `JSON.parse` you will get just a simple plain (literal) JavaScript object (just `Object` type);\n- it supports more advanced Object concepts such as **polymorphism** and **Object identity**;\n- it supports **cyclic object** serialization/deserialization;\n- it supports serialization/deserialization of other native JavaScript types: `Map`, `Set`, `BigInt`, Typed Arrays (such as `Int8Array`);\n\nThis library can be useful in more complex cases, for example when you want to:\n- manipulate JSON in depth;\n- restore a JavaScript type (a similar package is [class-transformer](https://github.com/typestack/class-transformer)); \n- preserve type information (using polymorphic type handling decorators: `@JsonTypeInfo`, `@JsonSubTypes`, and `@JsonTypeName`. A similar package is [TypedJSON](https://github.com/JohnWeisz/TypedJSON));\n- hide some properties for certain HTTP endpoints or some other external service;\n- have different JSON response for some external application or manage different JSON data coming from other application (for example you need to communicate with a Spring Boot application that uses different JSON Schema for the same model or with other applications made with Python, PHP, etc...);\n- manage cyclic references;\n- manage other JavaScript native types such as Maps and Sets;\n- etc.\n\nMost of the use cases of the Java [FasterXML/jackson](https://github.com/FasterXML/jackson) annotations are similar or equal.\n\n## Installation\n```\nnpm install --save jackson-js\n```\n\n## API\n\nAPI docs can be found [here](https://pichillilorenzo.github.io/jackson-js).\n\nThe main classes that `jackson-js` offers to serialize and deserialize JavaScript objects are: `ObjectMapper`, `JsonStringifier` and `JsonParser`.\n\n### ObjectMapper\n\n`ObjectMapper` provides functionality for both reading and writing JSON and applies `jackson-js` **decorators**. It will use instances of `JsonParser` and `JsonStringifier` for implementing actual reading/writing of JSON. It has two methods:\n- `stringify(obj: T, context?: JsonStringifierContext): string`: a method for serializing a JavaScript object or a value to a JSON string with **decorators** applied;\n- `parse(text: string, context?: JsonParserContext): T`: a method for deserializing a JSON string into a JavaScript object/value (of type `T`, based on the context given) with **decorators** applied.\n\n### JsonParser\n\n`JsonParser` provides functionality for writing JSON and applies `jackson-js` **decorators**. The main methods are:\n- `parse(text: string, context?: JsonParserContext): T` : a method for deserializing a JSON string into a JavaScript object/value (of type `T`, based on the context given) with **decorators** applied;\n- `transform(value: any, context?: JsonParserContext): any` : a method for applying `jackson-js` **decorators** to a JavaScript object/value parsed. It returns a JavaScript object/value with decorators applied.\n\n### JsonStringifier\n\n`JsonStringifier` provides functionality for reading JSON and applies `jackson-js` **decorators**. The main methods are:\n- `stringify(obj: T, context?: JsonStringifierContext): string`: a method for serializing a JavaScript object or a value to a JSON string with **decorators** applied;\n- `transform(value: any, context?: JsonStringifierContext): any`: a method for applying `jackson-js` **decorators** to a JavaScript object/value. It returns a JavaScript object/value with decorators applied and ready to be JSON serialized.\n\n### Decorators\n\nDecorators available:\n- [JsonAlias](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonalias) (decorator options: [JsonAliasOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonaliasoptions.html))\n- [JsonAnyGetter](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonanygetter) (decorator options: [JsonAnyGetterOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonanygetteroptions.html))\n- [JsonAnySetter](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonanysetter) (decorator options: [JsonAnySetterOptions](https://pichillilorenzo.github.io/jackson-js/latest/modules/types.html#jsonanysetteroptions))\n- [JsonAppend](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonappend) (decorator options: [JsonAppendOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonappendoptions.html))\n- [JsonBackReference](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonbackreference) (decorator options: [JsonBackReferenceOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonbackreferenceoptions.html))\n- [JsonClassType](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonclasstype) (decorator options: [JsonClassTypeOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonclasstypeoptions.html))\n- [JsonCreator](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsoncreator) (decorator options: [JsonCreatorOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsoncreatoroptions.html))\n- [JsonDeserialize](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsondeserialize) (decorator options: [JsonDeserializeOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsondeserializeoptions.html))\n- [JsonFilter](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonfilter) (decorator options: [JsonFilterOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonfilteroptions.html))\n- [JsonFormat](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonformat) (decorator options: [JsonFormatOptions](https://pichillilorenzo.github.io/jackson-js/latest/modules/types.html#jsonformatoptions))\n- [JsonGetter](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsongetter) (decorator options: [JsonGetterOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsongetteroptions.html))\n- [JsonIdentityInfo](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonidentityinfo) (decorator options: [JsonIdentityInfoOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonidentityinfooptions.html))\n- [JsonIdentityReference](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonidentityreference) (decorator options: [JsonIdentityReferenceOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonidentityreferenceoptions.html))\n- [JsonIgnore](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonignore) (decorator options: [JsonIgnoreOptions](https://pichillilorenzo.github.io/jackson-js/latest/modules/types.html#jsonignoreoptions))\n- [JsonIgnoreProperties](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonignoreproperties) (decorator options: [JsonIgnorePropertiesOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonignorepropertiesoptions.html))\n- [JsonIgnoreType](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonignoretype) (decorator options: [JsonIgnoreTypeOptions](https://pichillilorenzo.github.io/jackson-js/latest/modules/types.html#jsonignoretypeoptions))\n- [JsonInclude](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsoninclude) (decorator options: [JsonIncludeOptions](https://pichillilorenzo.github.io/jackson-js/latest/modules/types.html#jsonincludeoptions))\n- [JsonInject](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsoninject) (decorator options: [JsonInjectOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsoninjectoptions.html))\n- [JsonManagedReference](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonmanagedreference) (decorator options: [JsonManagedReferenceOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonmanagedreferenceoptions.html))\n- [JsonNaming](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonnaming) (decorator options: [JsonNamingOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonnamingoptions.html))\n- [JsonProperty](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonproperty) (decorator options: [JsonPropertyOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonpropertyoptions.html))\n- [JsonPropertyOrder](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonpropertyorder) (decorator options: [JsonPropertyOrderOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonpropertyorderoptions.html))\n- [JsonRawValue](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonrawvalue) (decorator options: [JsonRawValueOptions](https://pichillilorenzo.github.io/jackson-js/latest/modules/types.html#jsonrawvalueoptions))\n- [JsonRootName](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonrootname) (decorator options: [JsonRootNameOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonrootnameoptions.html))\n- [JsonSerialize](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonserialize) (decorator options: [JsonSerializeOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonserializeoptions.html))\n- [JsonSetter](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonsetter) (decorator options: [JsonSetterOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonsetteroptions.html))\n- [JsonSubTypes](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonsubtypes) (decorator options: [JsonSubTypesOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonsubtypesoptions.html))\n- [JsonTypeId](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsontypeid) (decorator options: [JsonTypeIdOptions](https://pichillilorenzo.github.io/jackson-js/latest/modules/types.html#jsontypeidoptions))\n- [JsonTypeIdResolver](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsontypeidresolver) (decorator options: [JsonTypeIdResolverOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsontypeidresolveroptions.html))\n- [JsonTypeInfo](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsontypeinfo) (decorator options: [JsonTypeInfoOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsontypeinfooptions.html))\n- [JsonTypeName](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsontypename) (decorator options: [JsonTypeNameOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsontypenameoptions.html))\n- [JsonUnwrapped](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonunwrapped) (decorator options: [JsonUnwrappedOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonunwrappedoptions.html))\n- [JsonValue](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonvalue) (decorator options: [JsonValueOptions](https://pichillilorenzo.github.io/jackson-js/latest/modules/types.html#jsonvalueoptions))\n- [JsonView](https://pichillilorenzo.github.io/jackson-js/latest/modules/decorators.html#jsonview) (decorator options: [JsonViewOptions](https://pichillilorenzo.github.io/jackson-js/latest/interfaces/types.jsonviewoptions.html))\n\n## Important note\n\nThe most important decorators are:\n- `@JsonProperty()`: each class property (or its getter/setter) must be decorated with this decorator, otherwise deserialization and serialization will not work properly! That's because, for example, given a JavaScript class, there isn't any way or API (such as [Reflection API for Java](https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/package-summary.html)) to get for sure all the class properties; also because, sometimes, compilers such as [TypeScript](https://www.typescriptlang.org/) and [Babel](https://babeljs.io/), can strip class properties after compilation from the class properties declaration;\n- `@JsonClassType()`: this decorator, instead, is used to define the type of a class property or method parameter. This information is used during serialization and, more important, during deserialization to know about **the type of a property/parameter**. This is necessary because JavaScript isn't a strongly-typed programming language, so, for example, during deserialization, without the usage of this decorator, there isn't any way to know the specific type of a class property, such as a `Date` or a custom Class type.\n\nHere is a quick example about this two decorators:\n```typescript\nclass Book {\n  @JsonProperty() @JsonClassType({type: () =\u003e [String]})\n  name: string;\n\n  @JsonProperty() @JsonClassType({type: () =\u003e [String]})\n  category: string;\n}\n\nclass Writer {\n  @JsonProperty() @JsonClassType({type: () =\u003e [Number]})\n  id: number;\n  @JsonProperty() @JsonClassType({type: () =\u003e [String]})\n  name: string;\n\n  @JsonProperty() @JsonClassType({type: () =\u003e [Array, [Book]]})\n  books: Book[] = [];\n}\n```\n\n## Tutorials\n- [Jackson-js: Powerful JavaScript decorators to serialize/deserialize objects into JSON and vice versa (Part 1)](https://itnext.io/jackson-js-powerful-javascript-decorators-to-serialize-deserialize-objects-into-json-and-vice-df952454cf?source=friends_link\u0026sk=a65bd247eca2f95fdfddda34447a6db6) - Article available at [[itnext.io](https://itnext.io/jackson-js-powerful-javascript-decorators-to-serialize-deserialize-objects-into-json-and-vice-df952454cf?source=friends_link\u0026sk=a65bd247eca2f95fdfddda34447a6db6) | [dev.to](https://dev.to/pichillilorenzo/jackson-js-powerful-javascript-decorators-to-serialize-deserialize-objects-into-json-and-vice-versa-part-1-5484)].\n- [Jackson-js: Examples for client (Angular) and server (Node.js) side (Part 2)](https://medium.com/@pichillilorenzo/jackson-js-examples-for-client-and-server-side-part-2-7e66df74c851?source=friends_link\u0026sk=2636fca640284894c63cb3c689a0e822) - Article available at [[medium.com](https://medium.com/@pichillilorenzo/jackson-js-examples-for-client-and-server-side-part-2-7e66df74c851?source=friends_link\u0026sk=2636fca640284894c63cb3c689a0e822) | [dev.to](https://dev.to/pichillilorenzo/jackson-js-examples-for-client-angular-and-server-node-js-side-part-2-128n)]\n\n## Examples\n\nCode examples can be found inside the `tests` folder and in [this example repository](https://github.com/pichillilorenzo/jackson-js-examples). The example repository gives a simple example using the `jackson-js` library with Angular 9 for the client side and two examples for the server side: one using Node.js + Express + SQLite3 (with Sequelize 5) and another one using Node.js + LoopBack 4.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpichillilorenzo%2Fjackson-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpichillilorenzo%2Fjackson-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpichillilorenzo%2Fjackson-js/lists"}