added a flag to encode/decode flattened data as json