Answer the question
In order to leave comments, you need to log in
Scheme for JSON. How to validate and replace incorrect properties?
Hello.
Suggest a JS library.
It is necessary to generalize the data received from the API.
For example
, there is a certain scheme (conditional):
const Scheme = {
"name": string,
"tags": array,
"stocks": object,
"someprop": string
}
[{
"name": "qwerty",
"tags": undefined,
"stocks": [1]
}]
[{
"name": "qwerty",
"tags": [],
"stocks": {},
"someprop": ''
}]
Answer the question
In order to leave comments, you need to log in
Schema JSON validation - practised . As for replacements and "auto-repair" - I have not seen this, maybe you need to customize the verification process according to the scheme, when you need to do something with an invalid element (throw away and put a stub according to the scheme).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question