json2fson
v1.0.15
Published
JavaScript Object Notation to FileSystem Object Notation
Maintainers
Readme
json2fson
JavaScript Object Notation to FileSystem Object Notation (json to fson) and back
Converts a JSON to a FSON and back:
Current status: Early alpha!
Installation
npm install --save json2fson
Usage
var json2fson = require("json2fson")
var data = {
//The object you want to convert
name: "John Doe",
age: 20,
colors: ["red", "green", "blue"],
friends: {
goodOnes: [
{
NAME: "Foo",
AGE: 20,
},
{
NAME: "Bar",
AGE: 30,
},
],
OTHERS: [
{
NAME: "FooBar",
AGE: 25.5,
},
],
},
homeAddress: "Main St. #180",
}
json2fson.convert({ data: data })Will create the following structure and contents inside the DB folder (./fson/ by default):
- ./
- fson/
- data/
- name (file containing
"John Doe") - age (containing
20) - colors/
- 0 (
"red") - 1 (
"green") - 2 (
"blue")
- 0 (
- friends/
- good_ones/
- 0/
- _n_a_m_e _(
"Foo")_ - _a_g_e _(
20)_
- _n_a_m_e _(
- 1/
- _n_a_m_e _(
"Bar")_ - _a_g_e _(
30)_
- _n_a_m_e _(
- 0/
- _o_t_h_e_r_s/
- 0/
- _n_a_m_e _(
"FooBar")_ - _a_g_e _(
25.5)_
- _n_a_m_e _(
- 0/
- good_ones/
- home*address *(
"Main St. #180")_
- name (file containing
- data/
- fson/
Running tests
Do npm install and npm test to create the FSON above.
FSON rules
The following rules are followed:
- Plain objects and arrays (strictly {...} and [...]) are folders
- Keys are files and values are file contents (i.e the object
{ name: "John" }will create a file called "name" containing"John"). - Uppercase letters have a leading low dash "_" since OS' paths are not always case sensitive.
