Change to use a LinkedHashMap for ordering.
Fix writeJSON functions to understand nested levels.