Function isJSONObject

  • Checks if a value is a JSON object.

    A valid JSON object is defined as an object with string keys and valid JSON values.

    Parameters

    • obj: unknown

      The value to check.

    Returns obj is Record<string, any>

    True if obj is a JSON object, false otherwise.

    isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
    isJSONObject({ regexp: /test/ }); // false
    isJSONObject(123); // false