APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
956 stars 228 forks source link

Feature Request: Handle presence of byte order marking #109

Closed dowlingw closed 7 months ago

dowlingw commented 5 years ago

According to RFC 7159, documents with a byte order mark are not valid JSON: https://tools.ietf.org/html/rfc7159#section-8.1

Implementations MUST NOT add a byte order mark to the beginning of a JSON text. In the interests of interoperability, implementations that parse JSON texts MAY ignore the presence of a byte order mark rather than treating it as an error.

However, there are a number of notable specifications published that violate the standard. Example: https://github.com/Azure/azure-resource-manager-schemas

It is currently possible to work around this by wrapping the inbuilt JSON parser with a custom parser that strips the offending characters.

Suggesting that this might be common enough that it's worth adding a flag to the JSON parser to handle this until the upstream sources are able to revise their specifications.

JamesMessinger commented 5 years ago

Great point! I definitely think this should be built-in functionality. I'd gladly accept a PR to add this.

dowlingw commented 5 years ago

Thanks, I've got the code to do this ready to go - will throw some tests around it and put together a PR as soon as possible, thanks!

jonluca commented 7 months ago

Added this feature to v11