Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@creately/jsonmix
Advanced tools
Easy to use deserialisation from JSON into JavaScript Objects complete with functions
JsonMix provides a kind of deserialisation from JSON into JavaScript Objects complete with functions.
import { JsonMix } from '@creately/jsonmix';
Use your existing model objects, without any modification. For example:
class Employee {
public firstName: string;
public lastName: string;
constructor(public id: string) {
//...
}
public getName() {
return this.firstName + ' ' + this.lastName;
}
}
And use your REST services, that go with your model:
{
"id": "001",
"firstName": "John",
"lastName": "Doe"
}
Finally use JsonMix to deserialize the JSON into model objects like this:
const mixer = new JsonMix(json);
const employee = await mixer.withObject(Employee).build();
With this simple tool you now have your JSON data deserialized into an object constructed from you model.
console.log(employee.getName());
A factory can also be used to create models.
const mixer = new JsonMix(json);
const employee = await mixer.withObject(data => new Employee(data.id)).build();
The factory can also return a prosmise which resolves to the model.
It's not uncommon to have multiple objects in a single JSON file, for example if you have an array of Employees in a JSON:
{
"employees": [
{
"id": "001",
"firstName": "John",
"lastName": "Doe"
},
{
"id": "002",
"firstName": "John",
"lastName": "Malkowich"
},
]
}
To apply Epmloyee to the entire array available on given path:
const mixer = new JsonMix(json);
const employees = await mixer.withObject(Employee, 'employees').build();
});
A slightly more complex example would look like:
const mixer = new JsonMix(json);
const result = await mixer
.withObject(Employee, 'employees')
.withObject(Pet, 'employees.pet')
.build();
// now you can use the nested model functions
console.log(result.employees[1].pet.getName());
The "path" can be any chain of nested objects separated with a dot. For example in this case "epmloyees.pet". JsonMix will find out if an object is an array, and will recursively apply the remaining part of the path to every item in it. You can also use "*" in the path, and this will apply the remaining path to every item in the object (even if it's not an array).
// this recursively applies the same prototype 3 levels deep
const mixer = new JsonMix(json);
const result = await mixer.withObject(Comparable, '*.*.*').build();
FAQs
Easy to use deserialisation from JSON into JavaScript Objects complete with functions
The npm package @creately/jsonmix receives a total of 3 weekly downloads. As such, @creately/jsonmix popularity was classified as not popular.
We found that @creately/jsonmix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.