1.0.0 ā¢ Published 4 years ago
mini-json v1.0.0
ā¤ļø mini-json
š Mini tool for json parser with typescript
š Getting started
š Install
npm install mini-json
- or -
yarn add mini-json
ā Usage
- š„ Object to json:
import MiniJson from 'mini-json';
const data = {
success: true,
data: {
dayOfBirthday: '19/07/2020',
name: 'mini-json'
}
};
console.log(MiniJson.toJson(data));
/*
{
"success": true,
"data": {
"day_of_birthday": "19/07/2020",
"name": "mini-json"
}
}
*/
- š¤ Json to object:
import MiniJson from 'mini-json';
const json = `{
"success": true,
"data": {
"day_of_birthday": "19/07/2020",
"name": "mini-json"
}
}`;
console.log(MiniJson.fromJson(json));
/*
{
success: true,
data: {
dayOfBirthday: '19/07/2020',
name: 'mini-json'
}
}
*/
ā Config
ā Default naming conventions of mini-json:
- toJson: camelCase to snakeCase
- fromJson: snakeCase to camelCase
š Global config for naming conventions
import MiniJson from 'mini-json';
import {camelCase, kebabCase} from 'lodash';
// toJson use camelCase naming convention
MiniJson.serializeKeysTo(camelCase);
// fromJson use kebabCase naming convention
MiniJson.deserializeKeysFrom(kebabCase);
ā Specify naming convention
import { kebabCase, camelCase } from 'lodash';
// fromJson use kebabCase naming convention
const student = MiniJson.fromJson<Student>(json, kebabCase);
// toJson use camelCase naming convention
const json = MiniJson.toJson(obj, camelCase);
š¶ Author
License
1.0.0
4 years ago