Technology moves fast! ⚡ Don't get left behind.🚶 Subscribe to our mailing list to keep up with latest and greatest in open source projects! 🏆


Subscribe to our mailing list

normalizr

Normalizes nested JSON according to a schema

Subscribe to updates I use normalizr


Statistics on normalizr

Number of watchers on Github 12252
Number of open issues 13
Average time to close an issue 13 days
Main language JavaScript
Average time to merge a PR 12 days
Open pull requests 19+
Closed pull requests 26+
Last commit over 1 year ago
Repo Created almost 5 years ago
Repo Last Updated over 1 year ago
Size 1.28 MB
Organization / Authorpaularmstrong
Latest Releasev3.2.0
Contributors21
Page Updated
Do you use normalizr? Leave a review!
View open issues (13)
View normalizr activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating normalizr for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

normalizr build status Coverage Status npm version npm downloads

Motivation

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.

Solution

Normalizr is a small, but powerful utility for taking JSON with a schema definition and returning nested entities with their IDs, gathered in dictionaries.

Documentation

Examples

Quick Start

Consider a typical blog post. The API response for a single post might look something like this:

{
  "id": "123",
  "author": {
    "id": "1",
    "name": "Paul"
  },
  "title": "My awesome blog post",
  "comments": [
    {
      "id": "324",
      "commenter": {
        "id": "2",
        "name": "Nicole"
      }
    }
  ]
}

We have two nested entity types within our article: users and comments. Using various schema, we can normalize all three entity types down:

import { normalize, schema } from 'normalizr';

// Define a users schema
const user = new schema.Entity('users');

// Define your comments schema
const comment = new schema.Entity('comments', {
  commenter: user
});

// Define your article 
const article = new schema.Entity('articles', { 
  author: user,
  comments: [ comment ]
});

const normalizedData = normalize(originalData, article);

Now, normalizedData will be:

{
  result: "123",
  entities: {
    "articles": { 
      "123": { 
        id: "123",
        author: "1",
        title: "My awesome blog post",
        comments: [ "324" ]
      }
    },
    "users": {
      "1": { "id": "1", "name": "Paul" },
      "2": { "id": "2", "name": "Nicole" }
    },
    "comments": {
      "324": { id: "324", "commenter": "2" }
    }
  }
}

Dependencies

None.

Credits

Normalizr was originally created by Dan Abramov and inspired by a conversation with Jing Chen. Since v3, it was completely rewritten and maintained by Paul Armstrong. It has also received much help, enthusiasm, and contributions from community members.

normalizr open issues Ask a question     (View All Issues)
  • over 2 years Set field on child entity based on parent entity on normalization
  • over 2 years Normalize different collections with a pre-flatted array
  • over 2 years Question: node package for normalised responses
  • over 2 years http://rackt.github.io/redux goes tp 404
  • over 2 years Django rest framework and normalizr
  • over 2 years Deeply Nested Schema Question
  • almost 3 years Will arrayOf support a parameter that not a schema?
  • almost 3 years index.d.ts should be in the same directory as index.js
  • almost 3 years [QUESTION] Normalize nested object
  • almost 3 years Allow dynamic schemaAttribute for children by checking a key on the parent-level
  • about 3 years normalize is take some time if object has more number of keys.
  • about 3 years Possibility to provide default values to a model
  • about 3 years Add examples
  • about 3 years Clean up tests
  • about 3 years Update & Organize Documentation
  • over 3 years Keep consistency for relations
  • over 3 years Dealing with collections keyed by ID without an ID in the entity itself
  • over 3 years Should empty arrays be preserved on their entity?
normalizr open pull requests (View All Pulls)
  • Allow EntitySchema-specific assignEntity fns
  • Add assignEntity option to IterableSchema
  • Add documentation for combined endpoints
  • Add type declarations
  • Make normalizr also copy Symbol keys
  • Polymorphic item creator
  • Possibility to provide default values for the entity
  • It should be possible to use relations
  • (feat) add ability to dynamically set nested schema type
  • Pass parent object to idAttribute.
  • (feat) add ability to dynamically set nested schema type
  • Can normalize entities keyed with their ID
  • Added schema option for assigning the parent id on the child entity
  • DOC: Clarify Entity idAttribute behavior
  • Refactored build process, distributing module entry
  • Adding Flux example
  • doc(roundtrip-example): Add round trip normalize/denormalize example
  • Fix type error for array+object shorthand
  • Add example how to rename a field
normalizr questions on Stackoverflow (View All Questions)
  • Normalizr: Merge 2 schemas from response into 1 normalized array?
  • How to reduce renders using redux + normalizr
  • How do I use Normalizr to handle basic nested JSON?
  • Normalizing simple array with normalizr
  • Normalize api response with normalizr
  • Normalizr - not resulting expected
  • React redux normalizr: how to deal with nested entities?
  • How do you add/remove to a redux store generated with normalizr?
  • Redux and Normalizr placing single entity into array
  • Redux + Normalizr detached (deleted) operation
  • Normalizr replacing SVG for PNG producing STRANGE results
normalizr list of languages used
normalizr latest release notes
v3.2.0 v3.2.0
  • Added Support denormoalizing from Immutable entities (gh-228)
  • Added Brought back get idAttribute() to schema.Entity (gh-226)
  • Fixed Gracefully handle missing data in denormalize (gh-232)
  • Fixed Prevent infinite recursion in denormalize (gh-220)
v3.1.0 v3.1.0 - denormalize
  • Added denormalize. (gh-214)
  • Changed No longer requires all input in a polymorphic schema (Array, Union, Values) have a matching schema definition. (gh-208)
  • Changed Builds do both rollup and plain babel file conversions. "main" property in package.json points to babel-converted files.
v3.0.1 v3.0.1
  • Fixes critical bug in some browsers with schema.Array. (#203)
Other projects in JavaScript