Skip to content

hugoalh/is-json-es

Is JSON (ES)

⚖️ MIT

GitHub: hugoalh/is-json-es JSR: @hugoalh/is-json NPM: @hugoalh/is-json

An ECMAScript module to determine whether the item is a JSON.

🎯 Targets

Runtime \ Source GitHub Raw JSR NPM
Bun >= v1.1.0 ✔️ ✔️
Deno >= v2.1.0 ✔️ ✔️ ✔️
NodeJS >= v20.9.0 ✔️ ✔️

🛡️ Runtime Permissions

This does not request any runtime permission.

#️⃣ Sources

  • 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}]
    

Note

  • 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).

⤵️ Entrypoints

Name Path Description
. ./mod.ts Default.

🧩 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

✍️ Examples

  • isJSON({
      a: 1,
      b: 2,
      c: 3,
      d: () => { }
    });
    //=> false
  • isJSON({
      a: 1,
      b: 2,
      c: 3,
      d: new Map()
    });
    //=> false
  • isJSON(NaN);
    //=> false
  • isJSON(void 0);
    //=> false
  • isJSON({
      a: 1,
      b: 2,
      c: 3
    });
    //=> true
  • isJSON([1, 2, 3]);
    //=> true

About

An ECMAScript module to determine whether the item is a JSON.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •