![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@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 0 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.