mi_json: complete rework of the module

consider the modules MI_IS_ARRAY hints to build a simpler JSON document
fixes cases where duplicate keys generate invalid documents
(example: ul_show_contacts)

(cherry picked from commit 459dffba91ebdda454a250fbad2eed2069eac8e2)