in reply to Create JSON file in specific format
The key point is that use JSON provides you with a Perl object that can both encode and decode ... "pretty" or not. To accomplish your task, you first construct the desired Perl data structure – in this case, an array of hashes – then you use that object to convert the structure into a JSON string. Or, vice-versa. In any case, the JSON object is treated as a black-box which is known to work correctly. You do not "build" the JSON string yourself. Simply trust that the object will do the right thing – because it will.