https://github.com/avdosev/normalizr_dart
A dart package for json normalization
https://github.com/avdosev/normalizr_dart
dart flutter json normalization normalize normalizr
Last synced: 3 days ago
JSON representation
A dart package for json normalization
- Host: GitHub
- URL: https://github.com/avdosev/normalizr_dart
- Owner: avdosev
- License: mit
- Created: 2022-02-21T18:48:00.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-27T11:40:37.000Z (almost 4 years ago)
- Last Synced: 2025-10-23T03:43:14.288Z (4 months ago)
- Topics: dart, flutter, json, normalization, normalize, normalizr
- Language: Dart
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# normalizr · 
Simple package for json normalization just like [normalizr](https://github.com/paularmstrong/normalizr).
## About
Many APIs, public or not, return JSON data that has deeply nested objects. Using data in this kind of structure is often very difficult.
Normalizr is a small, but powerful utility for taking JSON with a schema definition and returning nested entities with their IDs, gathered in dictionaries.
## Links
[Pub dev][pubdev]
[Documentation][docs]
[Issue tracker][tracker]
## Usage
Example input json
```json
{
"id": "123",
"author": {"id": "1", "name": "Paul"},
"title": "My awesome blog post",
"comments": [
{
"id": "324",
"commenter": {"id": "2", "name": "Nicole"}
}
]
}
```
Normalize:
```dart
import 'package:normalizr/normalizr.dart';
import 'dart:convert';
// Define a users schema
final user = Entity('users');
// Define your comments schema
final comment = Entity('comments', {
'commenter': Ref('users'),
});
// Define your article
final article = Entity('articles', {
'author': Ref('users'),
'comments': Ref.list('comments'),
});
void main() {
// setup
normalizr.addAll([user, comment, article]);
final data = ... // some json
// normalize json data
final normalizedData = normalize(data, article);
// output
final encoder = JsonEncoder.withIndent(' ');
String prettyJson = encoder.convert(normalizedData);
print(prettyJson);
}
```
output:
```json
{
"result": "123",
"type": "articles",
"entities": {
"users": {
"1": {
"id": "1",
"name": "Paul"
},
"2": {
"id": "2",
"name": "Nicole"
}
},
"comments": {
"324": {
"id": "324",
"commenter": "2"
}
},
"articles": {
"123": {
"id": "123",
"author": "1",
"title": "My awesome blog post",
"comments": [
"324"
]
}
}
}
}
```
## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[tracker]: https://github.com/avdosev/normalizr_dart/issues
[pubdev]: https://pub.dev/packages/normalizr
[docs]: https://pub.dev/documentation/normalizr/latest/