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

update json object with key. #397

Closed
vehere-ccu1 opened this issue Jan 16, 2018 · 2 comments
Closed

update json object with key. #397

vehere-ccu1 opened this issue Jan 16, 2018 · 2 comments

Comments

@vehere-ccu1
Copy link

Hi,
I'm trying to update json object with key but it's not taking new value:-

Current json string is like[rules_list] :-
{
"324981": { "_id": 324981, "description": "Creating event Alert", "category": "Category Of the threat", "severity": 1,
"alert": { "enabled": false }, "mail": { "enabled": false, "to": "chirxxxxx_dey@outlook.com" }, "syslog": { "enabled": true },
"keyword": "hello*world", "condition": { "all": [ { "fact": "ip.src_city", "operator": "contains", "value": "mumba" } ] } }
}

rule_id_as_key="324981"
rule :-

"324981": { "_id": 324981, "description": "Creating event Alert", "category": "Category Of the threat", "severity": 1,
"alert": { "enabled": false }, "mail": { "enabled": false, "to": "chirxxxxx_dey@outlook.com" }, "syslog": { "enabled": true },
"keyword": "hello*world", "condition": { "all": [ { "fact": "ip.src_city", "operator": "contains", "value": "mumbai" } ] } } 

json_object_object_del(rules_list,rule_id_as_key);
json_object_object_add(rules_list,rule_id_as_key,rule);

Then After[rules_list] :-

{
"324981":""
}

@hawicz
Copy link
Member

hawicz commented Jan 18, 2018

How are you creating "rule"? Are you freeing it after calling json_object_object_add()? (you shouldn't be)

@vehere-ccu1
Copy link
Author

Thanks hawicz,

I fixed the issue,There is no problem with json-c.
After calling json_object_object_add(rules_list,rule_id_as_key,rule),
I was calling json_object_object_put(rule); [As json-c is new for me].

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