Many APIs, public or not, return JSON data that has deeply nested objects. Using data in this kind of structure is often very difficult for JavaScript applications, especially those using Flux or Redux.
Normalizr is a small, but powerful utility for taking JSON with a schema definition and returning nested entities with their IDs, gathered in dictionaries.
The following nested object:
[{
id: 1,
title: 'Some Article',
author: {
id: 1,
name: 'Dan'
}
}, {
id: 2,
title: 'Other Article',
author: {
id: 1,
name: 'Dan'
}
}]
Can be normalized to:
{
result: [1, 2],
entities: {
articles: {
1: {
id: 1,
title: 'Some Article',
author: 1
},
2: {
id: 2,
title: 'Other Article',
author: 1
}
},
users: {
1: {
id: 1,
name: 'Dan'
}
}
}
}
Normalizr is built for various environments
src/*
- CommonJS, unpacked files. These are the recommended files for use with your own package bundler and are the default in-point as defined by this modules
package.json
.
- CommonJS, unpacked files. These are the recommended files for use with your own package bundler and are the default in-point as defined by this modules
normalizr.js
,normalizr.min.js
normalizr.amd.js
,normalizr.amd.min.js
normalizr.umd.js
,normalizr.umn.min.js
normalizr.browser.js
,normalizr.browser.min.js
- IIFE / Immediately-Invoked Function Expression, suitable for use as a standalone script import in the browser.
- Note: It is not recommended to use packages like Normalizr with direct browser
<script src="normalizr.js"></script>
tags. Consider a package bundler like webpack, rollup, or browserify instead.