@inf3rno/appendable-json

0.1.0 • Public • Published

appendable-json

Build Status Appendable JSON based format

file format

By storing the following variable:

const example = [
    123,
    "Lorem,\nipsum."
];

I started with a JSON array.

[123,"Lorem,\nipsum."]

Our main problem with the JSON format, that the square brackets make it hard to append without parsing. So I removed the square brackets.

123,"Lorem,\nipsum."

This is not bad, we could append it by adding ,"next", but I don't like that the first item is different, so I added comma at the end.

123,"Lorem,\nipsum.",

Now if we want to parse only the second item, then we have a problem to find it without parsing the whole string, because the lorem ipsum string contains a comma. I added a line break after the separator comma to solve this. Since the compact JSON coming from JSON.stringify does not contain any line break, this should suffice.

123,
"Lorem,\nipsum.",

I like this format, because it is easy to parse and build and it is great for logging or for file based event storages.

docs

installation

npm install @inf3rno/appendable-json

usage

const aJSON = require("@inf3rno/appendable-json");

serialization

const string = aJSON.stringify([{a:1},{b:2},{c:3}]);
const appended = string + aJSON.stringify([{d:4},{e:5}]);

unserialization

const array = aJSON.parse(string);

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i @inf3rno/appendable-json

    Weekly Downloads

    7

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    4.21 kB

    Total Files

    5

    Last publish

    Collaborators

    • inf3rno