The absolute state of C

json_t *fields=json_object();
json_t *auth=json_object();
json_t *auth_identity=json_object();
json_t *auth_identity_methods=json_array();
json_t *auth_identity_methods_password=json_string("password");
json_array_append(auth_identity_methods,auth_identity_methods_password);
json_object_set_new(auth_identity,"methods",auth_identity_methods);
json_t *auth_identity_password=json_object();
json_t *auth_identity_password_user=json_object();
json_t *auth_identity_password_user_name=json_string(token_request.username);
json_object_set_new(auth_identity_password_user,"name",auth_identity_password_user_name);
json_t *auth_identity_password_user_domain=json_object();
json_t *auth_identity_password_user_domain_id=json_string(token_request.userdomain);
json_object_set_new(auth_identity_password_user_domain,"id",auth_identity_password_user_domain_id);
json_object_set_new(auth_identity_password_user, "domain", auth_identity_password_user_domain);
json_t *auth_identity_password_user_password=json_string(token_request.password);
json_object_set_new(auth_identity_password_user, "password", auth_identity_password_user_password);
json_object_set_new(auth_identity_password, "user", auth_identity_password_user);
json_object_set_new(auth_identity, "password", auth_identity_password);
json_object_set_new(auth, "identity", auth_identity);
json_t *auth_scope=json_object();
json_t *auth_scope_project=json_object();
json_t *auth_scope_project_name=json_string(token_request.project);
json_object_set_new(auth_scope_project, "name", auth_scope_project_name);
json_t *auth_scope_project_domain=json_object();
json_t *auth_scope_project_domain_id=json_string(token_request.projectdomain);
json_object_set_new(auth_scope_project_domain, "id", auth_scope_project_domain_id);
json_object_set_new(auth_scope_project, "domain", auth_scope_project_domain);
json_object_set_new(auth_scope, "project", auth_scope_project);
json_object_set_new(auth,"scope",auth_scope);

Attached: serveimage.jpg (490x343, 51K)

Header files is a cancer

Learning c so I'mma guess this is just a bunch of pointers to what ever the method returns, the variable type being json_t

I'm assuming json_t is improted or defined already by typedef. I don't know anything about JavaScript.


Regardless this looks like a lot of shit for no reason.

Is this what you want to create?
fields = {
"auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": username,
"domain": { "id": userdomain },
"password": password
}
}
},
"scope": {
"project": {
"name": project,
"domain": { "id": projectdomain }
}
}
}
}

Yeah, this is the actual json I wanna create. As far as I'm concerned there's no clean way to generate it (like dictionaries or something similar.)

No u

Create a template JSON file and fill in the values instead of generating one completely from scratch.

If you still want it to be one self-contained executable, use xxd to include the template JSON within the executable.

>state of C
Why not to python instead?

Attached: govnocode.webm (640x360, 2.35M)

>method
function*

Use snprintf

I have to bring an alternative framework. Python was already shown in class. Plus I'm autist.

>As far as I'm concerned there's no clean way to generate it (like dictionaries or something similar.)
Its simply enough you can just use snprintf and not even need a JSON library

>tfw the c autist subtly corrupts your file

If you have already installed boost, it has a decent system called property trees. It has the most straightforward syntax I know.
Only problem with it is that when you write the value of a key, it will always have quotes around it because everything is a string to property trees. But you can manually remove the quotes and read it normally.
The syntax is like this:
ptree pt;
std::ifstream ifs(json_file);
read_json(ifs, pt);
int i;
pt.get(i, "path.to.value");
pt.put("new.value", 200);
write_json(json_file, pt);

The there are other operations like getting children and looping though a table, looping though an array, optional values, etc.
But to save you some trouble, if you haven't compiled boost before, look somewhere else.

But user, thats C++ not C.

I am dense strup :(
I guess I was thinking ahead of myself when OP posted

It looks like you're using Jansson. In that case, you can use json_pack to generate this json. It'll look something like this:
json_t *fields2 = json_pack("{ s:{s:{ s: [ s ], s: { s: { s: s, s: { s: s }, s: s } } }, s:{ s: { s: s, s: { s: s } } } } }", "auth", "identity", "methods", "password", "password", "user", "name", token_request.username, "domain", "id", token_request.userdomain, "password", token_equest.password, "scope", "project", "name", token_request.project, "domain", "id", token_request.projectdomain);


It's not perfect, but still better than this pointer pool you just made.

>inline definition of a JSON object

kys dude

> It's not perfect
Retarded.

That's unreadable in its own way.

json is a piece of shit. how anyone could think its better than xml is beyond me. xml has tags so its way easier to read and parse.

xml is the reason SOAP is able to exist so they should both fuck off and die

rust's serialization library serde does the same thing with quotes and makes you as_str() everything

Can't believe a low level language conceived in the 70s doesn't cope well with complex serialised data structures created decades later

Have you thought about Ruby C sharp or Java? You're not autistic you are an idiot.

What is the best way to parse JSON to a struct in C?