fix json tables saved as dictionnary

This was happening when you unset an entry in an array.
cf. http://stackoverflow.com/questions/3869129/php-json-encode-as-object-after-php-array-unset
fix json syntax when associatedFiles is empty

download is sucessful after sending a json dictionnary instead of json list

fixes #2088
clean buffer if there is something to clean

This was throwing multiple errors in logs
Merge remote-tracking branch 'fusinv/master'