
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
De/serialize json for consistency!
npm install jsonade
constructor
const mySerializer = new Serializer(resource, configuration, options);
resource (string)
: Name of the resource being serialized
configuration (Object)
: Configuration for serialisation
options (Object)
: Extra options for the serializer (optional)
Configuration:
attributes (Array)
: attributes to serializeOptions:
case
: Convert the case of the keys of data
Undefined
: Doesn't convert the casecamelCase
: Converts keys to camelCasesnake_case
: Converts keys to snake_casekebab-case
: Converts keys to kebab-caseReturns an instance of a custom serializer, ready to use for serializing data.
serialize
mySerializer.serialize(data, configuration);
data (Object|Array)
: Dataset to serialize.
configuration (Object)
: Configuration for serialisation
totalCount (Number) *optional
: When serializing an array, the totalCount is part of the meta object. If no totalCount is configured, the length of the provided dataset is used.Besides totalCount
, configuration
may be used to extend the meta
response object with arbitrary keys. The type
key however, cannot be overwritten.
Returns a serialized data respresentation of the given data.
serialize
error (Object|Array)
: Error(s) to serialize.
const errors = ErrorSerializer.serialize([error]);
errors (Object)
: object containing multiple errors.Every error can have these properties:
key | |
---|---|
status | required |
title | required |
id | optional |
code | optional, application specific |
detail | optional |
meta | optional |
{
"errors": [
{
"id": "ba4b9f14-5b83-4dfd-ac46-1c3868e1b3ec",
"status": 400,
"code": "2006",
"title": "Article not found",
"detail": "Article with id 892bb574-090d-4d63-a5b5-cb928d5f5c5f not found",
"meta": {
"stack": "NotFoundError: ..."
}
}
]
}
const { Serializer } = require('jsonade');
const userSerializer = new Serializer('user', {
attributes: ['firstName', 'lastName', 'address'],
address: {
attributes: ['street', 'number'],
},
});
const data = {
firstName: 'John',
lastName: 'Doe',
age: 27,
address: {
street: 'Markt',
number: '100',
city: 'Zonnedorp',
country: 'Belgium',
},
};
const result = userSerializer.serialize(data);
// result:
// {
// meta: {
// type: 'user'
// },
// data: {
// firstName: 'John',
// lastName: 'Doe',
// address: {
// street: 'Markt',
// number: '100',
// }
// }
// }
const data = [
{
firstName: 'John',
lastName: 'Doe',
age: 27,
address: {
street: 'Markt',
number: '100',
city: 'Zonnedorp',
country: 'Belgium',
},
}, {
firstName: 'Jessie',
lastName: 'Doe',
age: 26,
address: {
street: 'Marketstreet',
number: '101',
city: 'Sunvillage',
country: 'United Kingdom',
},
}
];
const result = userSerializer.serialize(data, { totalCount: 91 });
// result:
// {
// meta: {
// type: 'user',
// count: 2,
// totalCount: 91
// },
// data: [
// {
// firstName: 'John',
// lastName: 'Doe',
// address: {
// street: 'Markt',
// number: '100'
// }
// },
// { ... },
// ]
// }
const data = [
{
firstName: 'John',
lastName: 'Doe',
age: 25,
address: {
street: 'Markt',
number: '100',
city: 'Zonnedorp',
country: 'Belgium',
},
}, {
firstName: 'Jessie',
lastName: 'Doe',
age: 27,
address: {
street: 'Marketstreet',
number: '101',
city: 'Sunvillage',
country: 'United Kingdom',
},
}
];
const result = userSerializer.serialize(data, { totalCount: 91, averageAge: 26 });
// result:
// {
// meta: {
// type: 'user',
// count: 2,
// totalCount: 91
// averageAge: 26
// },
// data: [
// {
// firstName: 'John',
// lastName: 'Doe',
// address: {
// street: 'Markt',
// number: '100'
// }
// },
// { ... },
// ]
// }
const { Serializer } = require('jsonade');
const addressSerializer = new Serializer('address', {
attributes: ['street', 'number'],
});
const userSerializer = new Serializer('user', {
attributes: ['firstName', 'lastName', 'address'],
address: addresssSerializer,
});
const data = {
firstName: 'John',
lastName: 'Doe',
age: 27,
address: {
street: 'Markt',
number: '100',
city: 'Zonnedorp',
country: 'Belgium',
},
};
const result = userSerializer.serialize(data);
// result:
// {
// meta: {
// type: 'user'
// },
// data: {
// firstName: 'John',
// lastName: 'Doe',
// address: {
// street: 'Markt',
// number: '100'
// }
// }
// }
const { Serializer } = require('jsonade');
const userSerializer = new Serializer(
'user',
{ attributes: ['firstName', 'lastName', 'age', 'greeting'] },
{ case: 'snake_case' },
);
const data = {
firstName: 'John',
lastName: 'Doe',
age: '27',
};
const result = userSerializer.serialize(data);
// result:
// {
// meta: {
// type: 'user'
// },
// data: {
// first_name: 'John',
// last_name: 'Doe',
// age: '27 years old'
// greeting: 'Hello, I\'m John Doe',
// }
// }
const { Serializer } = require('jsonade');
const userSerializer = new Serializer('user', {
attributes: ['firstName', 'lastName', 'age', 'greeting'],
age: val => `${val} years old`,
greeting: (v, data) => `Hello, I'm ${data.firstName} ${data.lastName}`,
});
const data = {
firstName: 'John',
lastName: 'Doe',
age: '27',
};
const result = userSerializer.serialize(data);
// result:
// {
// meta: {
// type: 'user'
// },
// data: {
// firstName: 'John',
// lastName: 'Doe',
// age: '27 years old'
// greeting: 'Hello, I\'m John Doe',
// }
// }
const { ErrorSerializer } = require('jsonade');
const errorResponse = ErrorSerializer.serialize(ex);
This project is licensed under the ISC License - see the LICENSE.md file for details
FAQs
Json de/serialization made for consistency
The npm package jsonade receives a total of 22 weekly downloads. As such, jsonade popularity was classified as not popular.
We found that jsonade demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.