Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
object-unpacker
Advanced tools
This program takes a JSON object and convertes it to a new JSON object using a mapping specification, also written as JSON.
There are some examples of how to use the mapper in the test
directory, and a simple TypeScript
example follows:
// Import the Schema Mapper type
import { createObjectUnpacker } from './ObjectUnpacker';
// Create the schema mapper
const mapper = createObjectUnpacker();
// This is the data to be transformed
const data = {
"x": [
{
"a": [
"testa",
"testb"
],
"au": "%system.metadata.author"
}
]
};
// This is the transformation specification
const mapperData = {
"x": {
"rewriteKey": "expanded"
},
"a": {
"rewriteKey": "another",
"assignKeys": [
"s",
"t",
"u"
],
"rewriteValue": {
"first": "%s",
"second": "%t",
"third": "%u",
"fourth": "%/subs.system.metadata.name"
}
},
"au": {
"rewriteKey": "author"
}
};
// Entries in this object can be referenced by the `data` or the `mapperData`.
// E.g. `%system.metadata.name` and '%system.metadata.author'
const refs = {
system: {
metadata: {
name: 'The System Name',
author: 'A. Programmer',
},
},
};
// Apply the mapping to the data to get an `expanded` object
const expanded: object = mapper.convert(refs, data, mapperData);
// Pretty-print the resulting JSON.
console.log(JSON.stringify(expanded, null, 2));
JavaScript
const unpacker = require("object-unpacker")
// This is the data to be transformed
const data = {
"x": [
{
"a": [
"testa",
"testb"
],
"au": "%system.metadata.author"
}
]
};
// This is the transformation specification
const mapperData = {
"x": {
"rewriteKey": "expanded"
},
"a": {
"rewriteKey": "another",
"assignKeys": [
"s",
"t",
"u"
],
"rewriteValue": {
"first": "%s",
"second": "%t",
"third": "%u",
"fourth": "%/subs.system.metadata.name"
}
},
"au": {
"rewriteKey": "author"
}
};
// Entries in this object can be referenced by the `data` or the `mapperData`.
// E.g. `%system.metadata.name` and '%system.metadata.author'
const refs = {
system: {
metadata: {
name: 'The System Name',
author: 'A. Programmer',
},
},
};
// Apply the mapping to the data to get an `expanded` object
const expanded = unpacker.mapper.convert(refs, data, mapperData);
// Pretty-print the resulting JSON.
console.log(JSON.stringify(expanded, null, 2));
npm install
scratch.ts
in the src
directory.tsc
commandnode dist/scratch.js
tsc && node dist/scratch.js
The output should look like this:
{
"expanded": [
{
"another": {
"first": "testa",
"second": "testb",
"fourth": "The System Name"
},
"author": "A. Programmer"
}
]
}
npm install
npm install -g webpack
npm install -g webpack-cli
webpack
command in the project root directory.test/index.html
file using a web browser (Only tested using Brave browser)Execute
FAQs
A JSON to JSON mapper in TypeScript
The npm package object-unpacker receives a total of 3 weekly downloads. As such, object-unpacker popularity was classified as not popular.
We found that object-unpacker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.