[SR-Users] mongodb and jansson

Kelvin Chua kelchy at gmail.com
Mon Jul 6 11:43:24 CEST 2015


when using mongodb with jansson, intermittent failures will be seen because
jansson would change the order of keys inside a json object. mongodb would
expect the first key to be a command, for example "insert". this is
disastrous! below is a fix for jansson which will preserve the order on
which the json object was created.

--- modules/jansson/jansson_utils.c.old 2015-07-06 17:41:25.852770681 +0800
+++ modules/jansson/jansson_utils.c 2015-07-06 17:42:27.384769579 +0800
@@ -33,7 +33,7 @@
  val->flags = 0;

  if(json_is_object(v) || json_is_array(v)) {
- const char* value = json_dumps(v, JSON_COMPACT);
+ const char* value = json_dumps(v, JSON_COMPACT|JSON_PRESERVE_ORDER);
  *freeme = (char*)value;
  val->rs.s = (char*)value;
  val->rs.len = strlen(value);



Kelvin Chua
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20150706/ba6c35a3/attachment.html>


More information about the sr-users mailing list