https://github.com/chientrm/json2dir
Convert JSON object to directory tree. Auto mkdir recursively.
https://github.com/chientrm/json2dir
fs js json serialize
Last synced: 5 months ago
JSON representation
Convert JSON object to directory tree. Auto mkdir recursively.
- Host: GitHub
- URL: https://github.com/chientrm/json2dir
- Owner: chientrm
- Created: 2022-06-28T09:47:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-08T22:49:38.000Z (about 3 years ago)
- Last Synced: 2025-07-23T18:56:03.042Z (6 months ago)
- Topics: fs, js, json, serialize
- Language: JavaScript
- Homepage:
- Size: 205 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# json2dir
[](https://github.com/chientrm/json2dir/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/json2dir)
[](https://discord.com/invite/yy75DKs)
[](https://www.npmjs.com/package/json2dir)
[](https://www.npmjs.com/package/json2dir)
[](https://www.codacy.com/gh/chientrm/json2dir/dashboard?utm_source=github.com&utm_medium=referral&utm_content=chientrm/json2dir&utm_campaign=Badge_Grade)
[](https://www.codacy.com/gh/chientrm/json2dir/dashboard?utm_source=github.com&utm_medium=referral&utm_content=chientrm/json2dir&utm_campaign=Badge_Coverage)
- Convert JSON object to directory tree
- Auto `mkdir` recursively
- Zero dependencies
- Lightweight ~1 KB
## Install
```bash
npm install json2dir
```
## Types
```ts
json2dir(
dir: string,
serializers: Record string>,
obj: any
) : void
```
## Usage
```ts
import json2dir from 'json2dir'
import ini from 'ini'
const bob = { name: 'Bob', age: 23 }
json2dir(
'/root',
{
'.ini': ini.encode,
'.json': JSON.stringify
},
{
'a.json': bob,
'b.ini': { INFO: bob },
c: { d: { 'e.json': bob } },
'.sub/foo.bar/f.json': bob
}
)
```
### Results
```bash
/root
│ a.json
│ b.json
│
└───c/d
│ │
│ │ e.json
│
└───.sub/foo.bar
│
│ f.json
```
### Exceptions
If serializer is not provided, an exception will occur.
For example: `Error: No serializer for extension '.json'`
## Sponsor


