https://github.com/luisfuentech/object-dot-parser
Parse string dotted keys to nested attributes in object
https://github.com/luisfuentech/object-dot-parser
hacktoberfest json nodejs npm npm-package parser
Last synced: 2 months ago
JSON representation
Parse string dotted keys to nested attributes in object
- Host: GitHub
- URL: https://github.com/luisfuentech/object-dot-parser
- Owner: LuisFuenTech
- License: mit
- Created: 2021-08-29T22:05:36.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-02T22:10:31.000Z (over 4 years ago)
- Last Synced: 2024-08-09T13:14:17.810Z (almost 2 years ago)
- Topics: hacktoberfest, json, nodejs, npm, npm-package, parser
- Language: JavaScript
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Object Dot Parser
This module allows you to parse objects whose attributes are strings with points, and converts them into nested objects.
[](https://badge.fury.io/js/object-dot-parser)
[](https://github.com/LuisFuenTech/object-dot-parser/blob/master/LICENSE)
[](https://github.com/LuisFuenTech/object-dot-parser/blob/master/package.json)
[](https://packagephobia.now.sh/result?p=object-dot-parser)
[](http://npm-stat.com/charts.html?package=object-dot-parser)
# Compatibility
The minimum supported version of Node.js is v10.
# Usage
## Installation
```bash
$ npm i object-dot-parser
```
## Test
Run from the root folder:
```bash
$ npm run test
```
## Importing
```js
const objectDotParser = require('object-dot-parser');
```
## Example
```js
const objectDotParser = require('object-dot-parser');
const person = {
'person.name': 'Luis',
'person.age': 74,
'person.address.city': 'Atlanta',
'person.address.street.name': 'St. Joseph',
'person.address.street.number': '#34-46',
'person.position': 'Software Engineer',
'social.instagram': 'luisfuentech',
'social.twitter': 'luisfuentech',
'social.github': 'luisfuentech',
};
console.log(JSON.stringify(objectDotParser(person), null, 2));
```
Output
```bash
{
"person": {
"name": "Luis",
"age": 74,
"address": {
"city": "Atlanta",
"street": {
"name": "St. Joseph",
"number": "#34-46"
}
},
"position": "Software Engineer"
},
"social": {
"instagram": "luisfuentech",
"twitter": "luisfuentech",
"github": "luisfuentech"
}
}
```
# Contributing
If you want to add something or fix it, please follow [this guide](https://github.com/LuisFuenTech/object-dot-parser/blob/master/CONTRIBUTING.md)
# License
[MIT](https://github.com/LuisFuenTech/object-dot-parser/blob/master/LICENSE)