- Convert JSON object to directory tree
- Auto
mkdir
recursively - Zero dependencies
- Lightweight ~1 KB
npm install json2dir
json2dir(
dir: string,
serializers: Record<string, (obj: any) => string>,
obj: any
) : void
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
}
)
/root
│ a.json
│ b.json
│
└───c/d
│ │
│ │ e.json
│
└───.sub/foo.bar
│
│ f.json
If serializer is not provided, an exception will occur.
For example: Error: No serializer for extension '.json'