python - Mongo Insert Error - InvalidDocument - Key names must not contain the NULL byte -


when attempting insert following json document:

{   "cmd": "sync",   "deviceid": "applf4klr7xxxxxx",   "devicetype": "ipad",   "user": "jackxxxxx",   "\u0003\u0001j\u0000e\\ok\u00031102699800\u0000\u0001r\u000326\u0000\u0001s\u00030\u0000\u0001wx\u00033\u0000\u0001b\u00032\u0000\u0001\u0000\u0011ef\u00034\u0000\u0001g\u000332768\u0000\u0001\u0001\u0001\u0000\u0000vjm\u000326:4909\u0000\u0001\u0001\u0001\u0001\u0001\u0001": true } 

into mongo collection - error " invaliddocument - key names must not contain null byte".

the structure representing log line generated while logging ms activesync post requests towards owa server.

question is: safest way escape special char , yet keep new structure / value close possible original.

the problem last field key contains lot of unicode characters (include null byte \u0000):

\u0003\u0001j\u0000e\\ok\u00031102699800\u0000\u0001r\u000326\u0000\u0001s\u00030\u0000\u0001wx\u00033\u0000\u0001b\u00032\u0000\u0001\u0000\u0011ef\u00034\u0000\u0001g\u000332768\u0000\u0001\u0001\u0001\u0000\u0000vjm\u000326:4909\u0000\u0001\u0001\u0001\u0001\u0001\u0001 

the question want keep unicode in field key? if not try like

.decode('unicode_escape').encode('ascii','ignore')) 

taken this answer.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -