
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
one-hot-json
Advanced tools
on development
flattening and encoding JSON Objects
Many multivariate algorithms depend on array-like data. There is a need for modules to transform JSON Objects into such kind of data in a reasonable and easy to use manner. The main goal is to deliver a module with a generic encoding and decoding functionality for a collection of JSON Objects of the same Schema.
Flattening JSON Objects and encoding string values via one-hot approach.
const Onehot = require('one-hot-json');
const input = [
{
user: { id: 1, name: 'Dalton', prename: 'John', online: true },
project: { id: 1, name: 'lodash'},
},
{
user: { id: 1, name: 'Dalton', prename: 'John', online: true },
project: { id: 2, name: 'docdown'},
},
{
user: { id: 1, name: 'Dalton', prename: 'John', online: true },
project: { id: 3, name: 'lodash-cli'},
},
{
user: { id: 2, name: '-', prename: 'contra', online: false },
project: { id: 4, name: 'gulp'},
},
{
user: { id: 3, name: '-', prename: 'phated', online: true },
project: { id: 4, name: 'gulp'},
}
];
Initiate the one-hot-json transcriptor by a sample from targeting collection.
let sample = _.first(input);
const User = Onehot(sample);
let encoded: = User.encode(input);
// encoded:
[ [ 1, 0, 0, 2, 1, 0 ],
[ 1, 0, 0, 2, 2, 1 ],
[ 1, 0, 0, 2, 3, 2 ],
[ 2, 1, 1, 3, 4, 3 ],
[ 3, 1, 2, 2, 4, 3 ] ]
Decoding:
let decoded = User.decode(encoded);
console.log(JSON.stringify(input) === JSON.stringify(decoded));
//true
Usecase: encoded matrix as output from a replication or machine learning algorithms.
let deformatedEncoding = [
[ 0.9, 0.1, 0.2, 2.3, 0.8, 0.01 ],
[ 1.1, 0.2, 0.3, 2.2, 2.1, 1.35 ],
[ 0.8, 0.1, 0.1, 2.3, 3.2, 2.11 ],
[ 1.9, 0.9, 1.2, 3.1, 4.2, 3.31 ],
[ 2.9, 1.1, 2.2, 2.1, 4.3, 3.22 ]
];
let decodedDeformation = User.decode(deformatedEncoding);
console.log(JSON.stringify(input) === JSON.stringify(decodedDeformation));
//true
FAQs
flattening JSON Objects and encoding values via one-hot approach
We found that one-hot-json 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
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.