Gathering detailed insights and metrics for jsona
Gathering detailed insights and metrics for jsona
Gathering detailed insights and metrics for jsona
Gathering detailed insights and metrics for jsona
Tiny and simple JSON:API serializer / deserializer. Creates simplified objects from JSON or stored reduxObject, creates JSON from the same simplified objects (in according with JSON API specification)
npm install jsona
Typescript
Module System
Node Version
NPM Version
98.6
Supply Chain
100
Quality
78.5
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
6,257,911
Last Day
772
Last Week
29,561
Last Month
131,075
Last Year
1,595,361
MIT License
209 Stars
192 Commits
28 Forks
6 Watchers
3 Branches
13 Contributors
Updated on May 28, 2025
Minified
Minified + Gzipped
Latest Version
1.12.1
Package Id
jsona@1.12.1
Unpacked Size
135.91 kB
Size
25.57 kB
File Count
43
NPM Version
8.19.3
Node Version
16.19.0
Published on
Sep 23, 2023
Cumulative downloads
Total Downloads
1
7
JSON API v1.0 specification serializer and deserializer for use on the server and in the browser.
reduxObject
is a result object of json-api-normalizer)When you work with API standardized to json:api specification, you're dealing with a special and optimized JSON data format in the request and response body. You can get data of several entities that are related to each other, but you'll receive it in array (included). You may need to send modified back to server (or new data) in accordance with specification.
This may puzzle you with the following questions:
included
array many times more inconvenient and optimal?npm i jsona --save
or
yarn add jsona
You need to instantiate Jsona once, then use its public methods to convert data.
1import Jsona from 'jsona'; 2const dataFormatter = new Jsona();
1const json = { 2 data: { 3 type: 'town', 4 id: '123', 5 attributes: { 6 name: 'Barcelona' 7 }, 8 relationships: { 9 country: { 10 data: { 11 type: 'country', 12 id: '32' 13 } 14 } 15 } 16 }, 17 included: [{ 18 type: 'country', 19 id: '32', 20 attributes: { 21 name: 'Spain' 22 } 23 }] 24}; 25 26const town = dataFormatter.deserialize(json); 27console.log(town); // will output: 28/* { 29 type: 'town', 30 id: '123', 31 name: 'Barcelona', 32 country: { 33 type: 'country', 34 id: '32', 35 name: 'Spain' 36 }, 37 relationshipNames: ['country'] 38} */
1const user = { 2 type: 'user', 3 id: 1, 4 categories: [{ type: 'category', id: '1', name: 'First category' }], 5 town: { 6 type: 'town', 7 id: '123', 8 name: 'Barcelona', 9 country: { 10 type: 'country', 11 id: '32', 12 name: 'Spain' 13 }, 14 relationshipNames: ['country'] 15 }, 16 relationshipNames: ['categories', 'town'] 17}; 18 19const newJson = dataFormatter.serialize({ 20 stuff: user, // can handle array 21 includeNames: ['categories', 'town.country'] // can include deep relations via dot 22}); 23 24console.log(newJson); // will output: 25/* { 26 data: { 27 type: 'user', 28 id: 1, 29 relationships: { 30 categories: { 31 data: [{ type: 'category', id: '1' }] 32 }, 33 town: { 34 data: { type: 'town', id: '123' } 35 } 36 } 37 }, 38 included: [{ 39 type: 'category', 40 id: '1', 41 attributes: { 42 name: 'First category', 43 } 44 }, { 45 type: 'town', 46 id: '123', 47 attributes: { 48 name: 'Barcelona', 49 }, 50 relationships: { 51 country: { 52 data: { 53 type: 'country', 54 id: '32', 55 } 56 } 57 } 58 }, { 59 type: 'country', 60 id: '32', 61 attributes: { 62 name: 'Spain', 63 } 64 }] 65}*/
"reduxObject" - result object of json-api-normalizer
1const reduxObject = reduxStore.entities; // depends on where you store it 2const town = dataFormatter.denormalizeReduxObject({reduxObject, entityType: 'town', entityIds: '123'}); 3console.log(town); // if there is such town and country in reduxObject, it will output: 4/* { 5 type: 'town', 6 id: '123', 7 name: 'Barcelona', 8 country: { 9 type: 'country', 10 id: '34', 11 name: 'Spain' 12 }, 13 relationshipNames: ['country'] 14} */
You can control process of building simplified objects, just use your own propertyMappers when Jsona instantiates.
With IJsonPropertiesMapper you can implement your way of creation simplified objects (data models) from JSON, with IModelPropertiesMapper implement how to give back values from data model to JSON.
It gives unlimited possibilities to integrate Jsona with react, redux, angular2
Example of passing your own propertyMappers to Jsona:
1import Jsona from 'jsona'; 2import {MyModelPropertiesMapper, MyJsonPropertiesMapper} from 'myPropertyMappers'; 3 4export const dataFormatter = new Jsona({ 5 modelPropertiesMapper: MyModelPropertiesMapper, 6 jsonPropertiesMapper: MyJsonPropertiesMapper 7});
Also, there is built-in switchCasePropertyMappers, that you can use if need to automatically transform property names from kebab, snake, camel case and back.
For faster creation of simplified objects from json, it uses a cache for already processed json-entity, see DeserializeCache that uses by default. It possible to provide your own IDeserializeCache manager:
1import Jsona from 'jsona'; 2import {MyOwnDeserializeCache} from './index'; 3 4export const dataFormatter = new Jsona({ 5 DeserializeCache: MyOwnDeserializeCache 6});
Jsona, examples provided in this repository and in the documentation are MIT licensed.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
Found 2/15 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
-57.9%
772
Compared to previous day
Last Week
-10.1%
29,561
Compared to previous week
Last Month
-7.1%
131,075
Compared to previous month
Last Year
32.6%
1,595,361
Compared to previous year