class-validator
class-validator copied to clipboard
isJSON doesn't validate json-encoded strings
> import {Validator} from "class-validator";
{}
> const validator = new Validator();
undefined
> let json_str = JSON.stringify('abc');
undefined
> validator.isJSON(json_str);
false
However json-encoded objects and arrays are validated correctly:
> json_str = JSON.stringify({});
'{}'
> validator.isJSON(json_str);
true
> json_str = JSON.stringify([]);
'[]'
> validator.isJSON(json_str);
true
https://stackoverflow.com/questions/7487869/is-this-simple-string-considered-valid-json
Is string really valid JSON?
Any update on this?
@vlapo yes it is, the JSON specification states that a string is a valid Json https://datatracker.ietf.org/doc/html/rfc7159#section-3