You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Issues when adding values to firebase database #704
Hello, I'm having some issues adding values to a firebase database using this json library.
The test["pi"] adds into the firebase very well, but then when I try to add the test["pia"]["pia"] it responds with a "error" : "Invalid data; couldn't parse JSON object, array, or value."
test["asd2"] = {{"asd3","asd2"},{"asd4","asd5"}};
std::string s = test.dump();
std::cout << s << std::endl;
I get output {"asd2":{"asd3":"asd2","asd4":"asd5"}} from the cmd.
Now if I use libcurl from cmd, with input: curl -H 'Content-Type:application/json' -X PUT -d "{\"asd2\" :{\"asd3\": \"asd2\", \"asd4\":\"asd5\"}}" "https://....
I get the exact same output ( {"asd2":{"asd3":"asd2","asd4":"asd5"}} ), but only using libcurl from terminal succees.. What is going on?
Thank you very much for responding. I'm currently pulling my hair off because of this. Yes as you can see from this post it doesn't seem to need those single quotes anymore.. But here is what I got:
So, giving this exact input to my curl.exe straight from terminal (windows CMD) works;
curl -H 'Content-Type:application/json' -X PUT -d "{\"asd2\" :1.41, \"pi2\" : 2.82}" "https://
It inputs no problem; also giving raw string from my C++ program like this works;
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"pi\":1.41,\"pi2\":2.82}");
but then when I try to feed it with your json library output, it doesn't work:
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, j.dump());
and on top of that both "{\"pi\":1.41,\"pi2\":2.82}" and j.dump() seem exactly the same (at least to my eye) when printed out from my C++ program.
Well, storing both in a std::string and check if they are equal with == should be sufficient. It's just a guess, but the first thing I would try if they "look" the same, but treated differently.
Activity
jussihi commentedon Aug 22, 2017
I found this with a solution that I should wrap my JSON into single quotes:
https://stackoverflow.com/questions/33683757/firebase-invalid-data-couldnt-parse-json-object
Can I do it automatically with this json library?
jussihi commentedon Aug 22, 2017
More input; if I wirte this code:
I get output
{"asd2":{"asd3":"asd2","asd4":"asd5"}}from the cmd.Now if I use libcurl from cmd, with input:
curl -H 'Content-Type:application/json' -X PUT -d "{\"asd2\" :{\"asd3\": \"asd2\", \"asd4\":\"asd5\"}}" "https://....I get the exact same output (
{"asd2":{"asd3":"asd2","asd4":"asd5"}}), but only using libcurl from terminal succees.. What is going on?nlohmann commentedon Aug 22, 2017
No, adding single quotes around a JSON text is not supported by the library, but can be done without problems in client code.
Unfortunately, I do not understand your third comment #704 (comment). What is the issue?
jussihi commentedon Aug 22, 2017
Thank you very much for responding. I'm currently pulling my hair off because of this. Yes as you can see from this post it doesn't seem to need those single quotes anymore.. But here is what I got:
So, giving this exact input to my curl.exe straight from terminal (windows CMD) works;
curl -H 'Content-Type:application/json' -X PUT -d "{\"asd2\" :1.41, \"pi2\" : 2.82}" "https://
It inputs no problem; also giving raw string from my C++ program like this works;
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"pi\":1.41,\"pi2\":2.82}");
but then when I try to feed it with your json library output, it doesn't work:
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, j.dump());
and on top of that both "{\"pi\":1.41,\"pi2\":2.82}" and j.dump() seem exactly the same (at least to my eye) when printed out from my C++ program.
and more info: I'm using google firebase and its REST api documented here https://firebase.google.com/docs/reference/rest/database/
nlohmann commentedon Aug 22, 2017
That's weird. Can you make sure the strings are identical to the byte? There may be some subtle issue with escaping.
jussihi commentedon Aug 22, 2017
Can you point me a way to make clear they are identical?
Can I just memcmp with j.dump().data() and string.data() ?
nlohmann commentedon Aug 22, 2017
Well, storing both in a
std::stringand check if they are equal with==should be sufficient. It's just a guess, but the first thing I would try if they "look" the same, but treated differently.theodelrieu commentedon Aug 22, 2017
I might miss something here, but are you passing a
std::stringto the curl API?Does that even compile?
jussihi commentedon Aug 22, 2017
@nlohmann the strings are the same
@theodelrieu yes it does, without warnings. and now as you ask, yes, it works if I put in j.dump().data()
Now the firebase response is "No data supplied" :(
nvm, it works, you can close it. Thanks @theodelrieu for opening my eyes.
theodelrieu commentedon Aug 22, 2017
@jussihi It's because of varargs I guess, that's weird, glad it fixes your problem!