Closed ARao0123 closed 4 years ago
Since I can't see your whole json input file, let's say your complete input looks like:
{
"a": [{
"acvVersion": "0.5"
}, {
"vsId": 6547,
"algorithm": "AES-CFB128",
"isSample": false,
"testGroups": [{
"tgId": 1,
"testType": "AFT",
"tests": [{
"tcId": 1,
"iv": "F34481EC3CC627BACD5DC3FB08F273E6",
"pt": "00000000000000000000000000000000",
"key": "00000000000000000000000000000000"
}],
"direction": "encrypt",
"keyLen": 128
}]
}]
}
In this case, in order to get the result you mention in your description, you can try:
json_t *nested = json_array_get(json_object_get(json_array_get(
json_object_get(json_array_get(json_object_get(json, "a"), 1), "testGroups"),
0), "tests"), 0);
json_object_del(nested, "iv");
json_object_del(nested, "pt");
json_object_del(nested, "key");
json_object_set_new(nested, "ct", json_string("xxxxxxxx"));
Here json
is your input object. I don't think you need to call json_object_update to achieve your desired effect
Sorry for the late reply. The last comment I left was just an example. I checked your input file but I found that its content was different from your description at the begining. Could you describe which element you want to set/delete in your input file exactly?
I've the following content in my json input file (just part of file shown, it extend upto thousands of lines):
I've mocked up a small program to print the keys and values (following lines do all the job):
Output of this:
How can I add extra elements? I've tried "json_object_update_missing() and "json_object_update_existing() but may be I'm doing it wrong.
Here's what I want as my end result:
Any suggestions on how to do it? I tried the following (json is the object containing my input):