1.0.0 ā€¢ Published 4 years ago

mini-json v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

ā¤ļø mini-json

šŸ† Mini tool for json parser with typescript

GitHub

šŸ˜ 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

npm.ionpm.ionpm.ionpm.ionpm.ionpm.ionpm.ionpm.io

License

MIT