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

Trips up on sub JSON with query key #11

Open
kmpatel opened this issue Jan 10, 2022 · 5 comments
Open

Trips up on sub JSON with query key #11

kmpatel opened this issue Jan 10, 2022 · 5 comments

Comments

@kmpatel
Copy link

kmpatel commented Jan 10, 2022

e.g.

const char json[] = R"({"parent":{"child":"div"},"child":"span"})";

jsonExtract(json,"child");     // should return "span", instead returns "div"
@wyojustin
Copy link
Member

Thanks kmpatel for trying this lib and providing feedback! Did you call "jsonRemoveWhiteSpace()" first?

json = jsonRemoveWhiteSpace(json);

@kmpatel
Copy link
Author

kmpatel commented Jan 12, 2022

Oh. No, I did not use jsonRemoveWhiteSpace.
I saw it, but assumed it was a optional feature, not a mandatory step to parsing.

But is 'jsonRemoveWhiteSpace' a solution to subJSON with duplicate keys, or the beautified JSON?

@wyojustin
Copy link
Member

If I recall, will return first match for dups.

@kmpatel
Copy link
Author

kmpatel commented Jan 14, 2022

If I recall, will return first match for dups.

I don't think you are paying attention to the example. The example is a perfectly valid JSON with no actually duplicates; I should have written "apparent duplicate".

In the example, the call is to find the value of "child". Instead, the fn returns the value of "parent.child", which is the wrong member. It is a only a duplicate by appearance, when in fact it is valid member of sub-json "parent" that happens to appear before the target member "child".

@wyojustin
Copy link
Member

Yes, I beleive you have identified a bug in the code. The string searches are very rudimentary. I'll look to see if there is an easy way to fix this, but you may want to swich to a more robust libary.

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

2 participants