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

Forward slashes get escaped #446

Closed
pradeepsixer opened this issue Sep 2, 2018 · 1 comment
Closed

Forward slashes get escaped #446

pradeepsixer opened this issue Sep 2, 2018 · 1 comment

Comments

@pradeepsixer
Copy link

I have the following piece of code

struct json_object *claim_set = json_object_new_object();
json_object_object_add(claim_set, "iss", json_object_new_string("service_acct"));
json_object_object_add(claim_set, "scope", json_object_new_string("https://www.googleapis.com/auth/drive"));
json_object_object_add(claim_set, "aud", json_object_new_string("https://www.googleapis.com/oauth2/v4/token"));
json_object_object_add(claim_set, "iat", json_object_new_int64(epoch));
json_object_object_add(claim_set, "exp", json_object_new_int64(epoch + 3600));
printf("JSON Object : %s\n", json_object_to_json_string_ext(claim_set, JSON_C_TO_STRING_PLAIN));

And the output I get is:

{"iss":"service_acct","scope":"https:\/\/www.googleapis.com\/auth\/drive","aud":"https:\/\/www.googleapis.com\/oauth2\/v4\/token","iat":1535869316,"exp":1535872916}

Please note that the forward slashes are escaped in the stringified json, which shouldn't be.

@ploxiln
Copy link
Contributor

ploxiln commented Sep 2, 2018

It is something I've seen other json libraries do at times, I'll admit I'm not 100% sure why. Anyway, there's an option for that: JSON_C_TO_STRING_NOSLASHESCAPE
http://json-c.github.io/json-c/json-c-0.13/doc/html/json__object_8h.html#a5c11d72c55f3ab7c088f19e7bf118163

EDIT: just looked it up, it is in the original spec that you can escape the forward-slash, which it calls a "solidus", just in case I guess http://json.org/

@hawicz hawicz closed this as completed Sep 3, 2018
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

3 participants