Function isJSONString

  • Check whether it is a valid JSON string.

    Usage:

    const ret1 = isJSONString(`['a', 'b', 'c']`);
    const ret2 = isJSONString(`["a", "b", "c"]`);
    console.log(ret1);
    console.log(ret2);

    Output:

    false
    true
    

    Parameters

    • str: string

      The string to check.

    Returns boolean

    Return the result of checking.