Package detail

extract-first-json

bconnorwhite43kMIT2.0.2

Extract the first JSON object or array from a string

extract, json, object, array

readme

extract-first-json

NPM TypeScript


Extract the first JSON object or array from a string.


If I should maintain this repo, please ⭐️ GitHub stars

DM me on Twitter if you have questions or suggestions. Twitter


Installation

yarn add extract-first-json
npm install extract-first-json
pnpm add extract-first-json


Usage

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


Dependenciesdependencies


Dev Dependencies

  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.


License license

MIT

changelog

2.0.2 (2023-01-30)

Bug Fixes

  • remove unused dependency (e37aac3)

2.0.1 (2023-01-30)

2.0.0 (2023-01-30)

Bug Fixes

  • properly handle cases where an object is inside an array (9429fdc)