Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ruanyl/json-hoisting
https://github.com/ruanyl/json-hoisting
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/ruanyl/json-hoisting
- Owner: ruanyl
- License: mit
- Created: 2018-05-04T11:18:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-04T12:38:57.000Z (over 6 years ago)
- Last Synced: 2024-11-05T14:55:47.524Z (3 months ago)
- Language: TypeScript
- Size: 43.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## Format deep nested json data
#### Input deep nested json data
```
data = {
user: {
name: 'user1',
properties: {
age: 10,
relations: [
{
type: 'father',
properties: {
name: 'user2',
properties: {
age: 30
}
}
}, {
type: 'mother',
properties: {
name: 'user3',
properties: {
age: 32
}
}
}
]
}
}
}
```### Define the template
```
const schema = {
name: 'user.name',
age: 'user.properties.age',
parents: ['user.properties.relations', {
name: 'properties.name',
age: 'properties.properties.age'
}]
}
```#### Get the expected result
```
const expected = {
name: 'user1',
age: 10,
parents: [
{name: 'user2', age: 30},
{name: 'user3', age: 32}
]
}
expect(jsonHoisting(data, schema)).toEqual(expected)
```