fast-json-stringify | 2x faster than JSON.stringify | JSON Processing library
kandi X-RAY | fast-json-stringify Summary
kandi X-RAY | fast-json-stringify Summary
2x faster than JSON.stringify()
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Validate data .
- validate data
- infer type from schema
- Validate an Inc1 Inc .
fast-json-stringify Key Features
fast-json-stringify Examples and Code Snippets
const fastJson = require('fast-json-stringify')
const serial = fastJson({
type: 'object',
properties: {
response: {
oneOf: [
{ type: "string" },
{ type: "number" },
],
}
}
})
console.log(serial(5
Community Discussions
Trending Discussions on fast-json-stringify
QUESTION
What I want to do is add validation to the schema response from a fastify route.
Following the documentation from Fastify here we can see this
Ajv for the validation of a request fast-json-stringify for the serialization of a response's body
Related to improve and add validations for a response, what I want to do is check the schema when I send a response.
fast-json-stringify support different options, included format, but if you read the documentation, they said that they support JSON schema. Jsonschema has support for email format, that you can see here as a built-in format but when I try to use it on Fastify, like this:
...ANSWER
Answered 2021-Feb-10 at 14:22fast-json-stringify
does the serialization, not the validation.
The json schema provided to it will be used to serialize only the properties
declared and some type checking like integer
or array
s.
- the
enum
keyword is not supported - the
format
keyword is supported only for the dates as documented:
To reach your goal, you should use this plugin: fastify-response-validation
that will add a validation step of your response body before the serialization process.
QUESTION
So I have an app that needs to JSON.stringify
its data to put into localStorage, but as the data gets larger, this operation gets outrageously expensive.
So, I tried moving this onto a webWorker so it's off the main thread, but I'm now learning posting an object to a webWorker is even more expensive than stringifying it.
So I guess I'm asking, is there any way whatsoever to get JSON.stringify
off the main thread, or at least make it less expensive?
I'm familiar with fast-json-stringify
, but I don't think I can feasibly provide a complete schema every time...
ANSWER
Answered 2020-Mar-24 at 22:30You have correctly observed that passing object to web worker costs as much as serializing it. This is because web workers also need to receive serialized data, not native JS objects, because the instance objects are bound to the JS thread they were created in.
The generic solution is applicable to many programming problems: chose the right data structures when working with large datasets. When data gets larger it's better sacrifice simplicity of access for performance. Thus do any of:
Store data in indexedDBIf your large object contains lists of the same kind of entry, use indexed DB for reading and writing and you don't need to worry about serialization at all. This will require refactor of your code, but this is the correct solution for large datasets.
Store data in ArrayBufferIf your data is mostly fixed-size values, use an ArrayBuffer. ArrayBuffer can be copied or moved to web worker pretty much instantly and if your entries are all same size, serialization can be done in parallel. For access, you may write simple wrappers classes that will translate your binary data into something more readable.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install fast-json-stringify
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page