🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@inf3rno/appendable-json

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inf3rno/appendable-json

Appendable JSON based format

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
10
150%
Maintainers
1
Weekly downloads
 
Created
Source

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);

Keywords

JSON

FAQs

Package last updated on 27 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts