{"id":17254986,"url":"https://github.com/tejashah88/json-from-text","last_synced_at":"2026-05-11T07:46:56.213Z","repository":{"id":57284873,"uuid":"107202610","full_name":"tejashah88/json-from-text","owner":"tejashah88","description":"An algorithm for separating embedded JSON from a string, nicely packaged into a node.js module.","archived":false,"fork":false,"pushed_at":"2018-12-19T23:23:25.000Z","size":64,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T07:33:55.023Z","etag":null,"topics":["algorithm","json","json-parsing","json-string","nodejs","parsing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tejashah88.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-17T01:32:02.000Z","updated_at":"2022-08-27T17:22:03.000Z","dependencies_parsed_at":"2022-08-25T07:33:49.638Z","dependency_job_id":null,"html_url":"https://github.com/tejashah88/json-from-text","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tejashah88%2Fjson-from-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tejashah88%2Fjson-from-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tejashah88%2Fjson-from-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tejashah88%2Fjson-from-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tejashah88","download_url":"https://codeload.github.com/tejashah88/json-from-text/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245615009,"owners_count":20644376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","json","json-parsing","json-string","nodejs","parsing"],"created_at":"2024-10-15T07:10:24.376Z","updated_at":"2026-05-11T07:46:51.193Z","avatar_url":"https://github.com/tejashah88.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-from-text\n\n[![NPM Version](https://img.shields.io/npm/v/json-from-text.svg)](https://www.npmjs.com/package/json-from-text)\n[![Build Status](https://travis-ci.org/tejashah88/json-from-text.svg?branch=master)](https://travis-ci.org/tejashah88/json-from-text)\n[![Coverage Status](https://coveralls.io/repos/github/tejashah88/json-from-text/badge.svg)](https://coveralls.io/github/tejashah88/json-from-text)\n[![dependencies Status](https://david-dm.org/tejashah88/json-from-text/status.svg)](https://david-dm.org/tejashah88/json-from-text)\n\nAn algorithm for separating embedded JSON from a string, nicely packaged into an NPM module. It will attempt to parse potential JSON strings into objects and leave them as-is if it fails.\n\n## Upgrading from \u003c 1.0\nIf you are upgrading from \u003c 1.0, please see [UPGRADING](UPGRADING.md) for migration instructions.\n\n## Usage\n```javascript\nObject jsonFromText(String mixedStr, Boolean parseToObject)\n```\n\n### Parameters:\n* `mixedStr`: The string to separate the JSON from the text.\n* `parseToObject`: If set to `false`, the resulting JSON strings will not be translated to JSON objects. Default is `true`.\n\n## Example\n### Input\n```javascript\nvar jsonFromText = require('json-from-text');\nvar sampleText = \"There was a change from {'animal':'dog', 'color':'blue'} to {'animal':'cat', 'color':'red'}'\";\nvar results = jsonFromText(sampleText);\nconsole.log(JSON.stringify(results, null, 2));\n```\n\n### Output:\n```json\n{\n  \"textResults\": [\n    \"There was a change from '\",\n    \"' to '\",\n    \"'\"\n  ],\n  \"jsonResults\": [\n    {\n      \"animal\": \"dog\",\n      \"color\": \"blue\"\n    },\n    {\n      \"animal\": \"cat\",\n      \"color\": \"red\"\n    }\n  ],\n  \"fullResults\": [\n    {\n      \"type\": \"text\",\n      \"value\": \"There was a change from '\"\n    },\n    {\n      \"type\": \"json\",\n      \"parsed\": true,\n      \"value\": {\n        \"animal\": \"dog\",\n        \"color\": \"blue\"\n      }\n    },\n    {\n      \"type\": \"text\",\n      \"value\": \"' to '\"\n    },\n    {\n      \"type\": \"json\",\n      \"parsed\": true,\n      \"value\": {\n        \"animal\": \"cat\",\n        \"color\": \"red\"\n      }\n    },\n    {\n      \"type\": \"text\",\n      \"value\": \"'\"\n    }\n  ]\n}\n```\n\n## Mentions\n* [rjrodger](https://github.com/rjrodger) for his [jsonic](https://github.com/rjrodger/jsonic) module, which does lenient JSON parsing\n\n## License\nCopyright (c) 2017-2018 Tejas Shah\n\nMIT License, see [LICENSE](LICENSE.md) for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftejashah88%2Fjson-from-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftejashah88%2Fjson-from-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftejashah88%2Fjson-from-text/lists"}