Extract the first JSON object or array from a string
npm install extract-first-jsonExtract the first JSON object or array from a string.
_If I should maintain this repo, please ⭐️_
_DM me on Twitter if you have questions or suggestions._
---
``sh`
yarn add extract-first-json
`sh`
npm install extract-first-json
`sh`
pnpm add extract-first-json
`ts
import { extractJSON, extractJSONObject, extractJSONArray } from "extract-first-json";
const string = Example: { "ok": true };
const arrayString = Example: [{ "ok": true }];
extractJSON(string); // { ok: true }
extractJSONObject(string); // { ok: true }
extractJSONArray(arrayString); // [{ "ok": true }]
``
- parse-json-object: Parse a typed JSON object from a string
- reduce-first: Return early from reduce
- autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.