[ovs-dev] [ovsdb monitors 4/8] json: Better handle JSON objects with duplicate names.

Ben Pfaff blp at nicira.com
Wed Jun 30 23:49:23 UTC 2010


RFC 4627 (which defines JSON) says:

    The names within an object SHOULD be unique.

In my view, this means that the treatment of duplicate names within a
JSON object is more or less up to the implementation.  Until now, the OVS
JSON parser has dealt with duplicates fairly badly: they all get shoved
into the hash table and you get one or the other value semi-randomly
(typically the one added later).  This commit makes the behavior
predictable: old values are deleted and replaced by newer values.
---
 lib/json.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/json.c b/lib/json.c
index 10fa3c1..d26c89e 100644
--- a/lib/json.c
+++ b/lib/json.c
@@ -277,7 +277,7 @@ json_real_create(double real)
 void
 json_object_put(struct json *json, const char *name, struct json *value)
 {
-    shash_add(json->u.object, name, value);
+    json_destroy(shash_replace(json->u.object, name, value));
 }
 
 void
-- 
1.7.1





More information about the dev mailing list