@hugoalh/is-json
v1.0.6
Published
A module to determine whether the item is a JSON.
Readme
Is JSON (ES)
🔗 DistBoard @hugoalh ● GitHub ● JSR ● NPM
An ECMAScript module to determine whether the item is a JSON.
🎯 Runtime Targets
Any runtime which support ECMAScript should able to use this; These runtimes are officially supported:
🛡️ Runtime Permissions
This does not request any runtime permission.
#️⃣ Sources & Entrypoints
- GitHub Raw
https://raw.githubusercontent.com/hugoalh/is-json-es/{Tag}/mod.ts - JSR
jsr:@hugoalh/is-json[@{Tag}] - NPM
npm:@hugoalh/is-json[@{Tag}]
| Name | Path | Description |
|:--|:--|:--|
| . | ./mod.ts | Default. |
[!NOTE]
- Different runtimes have vary support for the sources and entrypoints, visit the runtime documentation for more information.
- It is recommended to include tag for immutability.
- These are not part of the public APIs hence should not be used:
- Benchmark/Test file (e.g.:
example.bench.ts,example.test.ts).- Entrypoint name or path include any underscore prefix (e.g.:
_example.ts,foo/_example.ts).- Identifier/Namespace/Symbol include any underscore prefix (e.g.:
_example,Foo._example).
🧩 APIs
function isJSON(item: unknown): item is JSONValue;function isJSONArray(item: unknown): item is JSONArray;function isJSONObject(item: unknown): item is JSONObject;function isJSONPrimitive(item: unknown): item is JSONPrimitive;
[!NOTE]
- For the full or prettier documentation, can visit via:
✍️ Examples
isJSON({ a: 1, b: 2, c: 3, d: () => { } }); //=> falseisJSON({ a: 1, b: 2, c: 3, d: new Map() }); //=> falseisJSON(NaN); //=> falseisJSON(void 0); //=> falseisJSON({ a: 1, b: 2, c: 3 }); //=> trueisJSON([1, 2, 3]); //=> true
