UNPKG

util-ex

Version:

Browser-friendly enhanced util fully compatible with standard node.js

16 lines (15 loc) 588 B
/** * Checks if a string is a valid JSON string. * * @param {string} v - The string to be checked. * @param {boolean=} almost - If true, only checks if the string is almost JSON-like. Defaults to false. * @returns {boolean} - Returns true if the string is valid JSON, false otherwise. * * @example * isJson('{"name": "John", "age": 30}'); // true * isJson('[1, 2, 3]'); // true * isJson('{"name": "John", "age": 30'); // false * isJson('This is not a JSON string.'); // false */ export function isJson(v: string, almost?: boolean | undefined): boolean; export default isJson;