Some common questions you might have when first learning Superstruct.
object struct validates that a value matches a known object shape. Just like it's TypeScript counterpart, it does not allow unknown keys—this is very useful in catching bugs in the majority of cases.
However, there are cases where you'd like to validate a set of properties but ignore any unknown ones. For that you can use the
type struct which is more generic, and acts similar to TypeScript's structural typing in that it does not care about any extra properties.
There are also cases where you want to "mask" an input object to remove any unknown keys without considering it invalid. In this case you can use the
The problem with a built-in
json struct is that it needs to recursively iterate through deep objects to guarantee they're valid JSON. What's wrong with that? Nothing, except that it would be a footgun.
The cases where you receive a truly unknown object, and you need to validate nothing about its content other than that it is pure JSON are very rare. In those cases, it's not hard to write a
json utility yourself.