Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion: handling the BOM in json text #55

Open
Dongmuliang opened this issue Dec 26, 2022 · 0 comments
Open

suggestion: handling the BOM in json text #55

Dongmuliang opened this issue Dec 26, 2022 · 0 comments

Comments

@Dongmuliang
Copy link

Hi, I find a rare case when utf-8 byte order mark (BOM) \xef\xbb\xbf involved.

Specifically, it will reject the json text when handling such case:

const char *s = "\xef\xbb\xbf{\"a\": [null, 1]}";
char *p;
int n;
int len = strlen(s);
int parsed_res = mjson_find(s, len, "$", &p, &n);

when we print the parsed_result, the value is 0, indicating the input json text is invalid.

JSON message exchanged in different platforms (e.g., Desktop and Embedded device) may contain the BOM prefix,
and the specification suggests we can (not a must) ignore that prefix.
Meanwhile, I checked that multiple JSON implementations in other platforms such as https://github.com/nlohmann/json, https://github.com/alibaba/AliOS-Things/tree/master/components/cjson really ignored the prefix, and they correctly parsed the json text.
Therefore, it would be better if this implementation also ignore the BOM prefix, thus can provide better interoperability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant