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