When using Yup version 1.3.3, there is a change in behavior compared to version 0.32.11 when validating JSON strings with array and object schemas.
Tej81r opened this issue · comments
Code that worked in Yup 0.32.11:
const schema1 = yup.array();
const argument = '[{"param1": "val1", "param2": "val2"}]';
params = await schema1.validate(argument);
Error with Yup 1.3.3:
this must be a array
type, but the final value was: `"[{"param1":"val1","param2":"val2"}]"`
Expected Behavior:
The validation should work as it did in version 0.32.11, allowing the automatic parsing of JSON strings when validating against array and object schemas.
Similar Issue with Object Schema:
In addition to the reported issue with array schemas, the same behavior is observed when using object schemas. Here's an example:
const schema2 = yup.object();
const argumentObject = '{"param1": "val1", "param2": "val2"}';
paramsObject = await schema2.validate(argumentObject);
Error with Yup 1.3.3:
this must be an object
type, but the final value was: `"{"param1": "val1", "param2": "val2"}"`
Expected Behavior:
The validation for object schemas should also work as expected, allowing automatic parsing of JSON strings.
correct there is a change in behavior json is not automatically parsed anymore, you can use json()
method now . Please see the changelogs and guides for migrating