echo json_encode pretty code example Example: js json_encode pretty var str = JSON.stringify(obj, null, 2); // spacing level = 2