https://github.com/yakiisama/extract-pure-json
https://github.com/yakiisama/extract-pure-json
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/yakiisama/extract-pure-json
- Owner: yakiisama
- Created: 2023-03-21T15:19:17.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-22T07:35:40.000Z (about 2 years ago)
- Last Synced: 2025-03-13T11:05:47.415Z (3 months ago)
- Language: TypeScript
- Size: 63.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Install
```sh
npm install extract-pure-json
```
```sh
yarn add extract-pure-json
```
```sh
pnpm install extract-pure-json
```# Usage
```js
import extractPureJson from 'extract-pure-json'const str1 = 'hello world { "a": 1, "b": 2 }'
const str2 = 'Hey [{ "a": 1, "b": 2 }]'
const str3 = '{"a": 1} {"b": 2}'
const str4 = '{"a": 1]*&^)}}}}}}'extractPureJson(str1) // { "a": 1, "b": 2 }
extractPureJson(str2) // false
extractPureJson(str3) // {"a": 1}
// sometimes the string is so long
// maybe it has not json style ,you can use retry option
extractPureJson(str4, {retry: 10}) // false
```