
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
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
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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.