
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Encode (as JSON) and parse both current and next-generation JavaScript data objects including Maps and Sets.
JsonNext is an npm package for encoding (as JSON) and parsing both current and next-generation JavaScript data objects including Maps and Sets.
npm install json-next
In order to use JsonNext, you must be in an environment which has Maps and Sets. Many browsers do not support those yet, so you will need to use something like babel-polyfill
to add those data types.
First there was ES5, then ES6, then ES2015/16/17 or just ESNext. JavaScript is moving forward and we now have Set
and Map
data types. These are wonderful to use, but cannot be directly serialized as JSON. JsonNext gives you the same basic stringify
and parse
methods that you are used to using with JavaScript, but allows you to pass in data which includes Sets and Maps, nested as deeply as you want. Currently, if you pass a Map
or Set
into JSON.stringify()
, they will be encoded as {}
and all your data will be lost. You can write your own methods for converting your data into traditional data types if you would like, or you can just use jsonNext.
First, import/require the lib:
import jsonNext from 'json-next';
Or, if you are using the older syntax:
var jsonNext = require('json-next').default;
Take some data and encode it as JSON.
// get some data
const myObj = {
someMap: new Map([ ['name', 'Ryan'], ['wife', 'Hannah'] ]),
someSet: new Set([ 5325, 24324, 41243, 4, 525, 2, 54325, 432, 5 ]),
mapOfSets: new Map([
['set1', new Set([ 'something', 'else', 'here' ])],
['set2', new Set([ new Map(), new Map(), new Map() ])]
]),
num: 300,
obj: {some: 'object'}
};
// stringify it
const jsonStr = jsonNext.stringify(myObj);
// if you want the JSON string to be formatted and pretty, pass in an object with pretty set to true
const prettyJson = jsonNext.stringify(myObj, {pretty: true});
When you want it back, just parse
it.
const myNewObj = jsonNext.parse(jsonStr);
// your data is back, exactly the way it began
console.log(myNewObj);
stringify
method. This allows you to quickly, deeply, and synchronously stringify all of your data (just like JSON.stringify
). But, this also means there are limitations on how large your data sets can be. I plan to add an async
flag to the options object which will allow you to encode asynchronously. It will be non-blocking and remove any limitations to data size.Run the tests:
npm test
Re-compile the source code:
npm run build
Watch the src
directory and automatically recompile on changes:
npm run watch
Contributions are welcome! If you have any issues and/or contributions you would like to make, feel free to file an issue and/or issue a pull reuqest.
Apache License Version 2.0
Copyright (c) 2016 by Ryan Burgett.
FAQs
Encode (as JSON) and parse both current and next-generation JavaScript data objects including Maps and Sets.
We found that json-next demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.