Attempts to normalize a string by unescaping it until it can be parsed as a JSON object,
then stringifies it exactly once. If the input is a regular string that does not represent
a JSON object or array, the function will return it as is without modification.
This function is designed to handle cases where strings might be excessively escaped due
to multiple layers of encoding, ensuring that JSON data is stored in a consistent and
predictable format, and regular strings are left unchanged.
Parameters
input: string
The potentially excessively escaped string.
Returns string
A string that is either the JSON.stringify version of the original JSON object
or the original string if it does not represent a JSON object or array.
Attempts to normalize a string by unescaping it until it can be parsed as a JSON object, then stringifies it exactly once. If the input is a regular string that does not represent a JSON object or array, the function will return it as is without modification. This function is designed to handle cases where strings might be excessively escaped due to multiple layers of encoding, ensuring that JSON data is stored in a consistent and predictable format, and regular strings are left unchanged.