utop # let str = "\"Foo\xc0\xafBar\"";;
val str : string = "\"FooÀ¯Bar\""
utop # Yojson.Basic.from_string str;;
- : Yojson.Basic.t = `String "FooÀ¯Bar"
utop # String.is_valid_utf_8 str;;
- : bool = false
I believe the string above is not legal UTF-8 but is accepted by the parser. Given that JSON is typically read from an external source it would be best to detect illegal UTF-8 during parsing.