properly null-terminate formatted json strings