Whenever we pass in input for validation, AJV will output the validated input. But it mutates the original input. Is there a way to prevent this?
Asked
Active
Viewed 224 times
1 Answers
0
It's been asked in the issue #549.
Ajv only mutates the data if there are options that ask Ajv to mutate it: removeAdditional, useDefaults, coerceTypes. Without these options the data is not changed.
There is no general way to copy the object in JavaScript so if you want to both apply the changes and to preserve the original data you need to copy the object in your code, which in a your case can be as simple as JSON.parse(JSON.stringify())
but in general case can be either much more complex or even not possible.

esp
- 7,314
- 6
- 49
- 79