json-from-text
An 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.
Upgrading from < 1.0
If you are upgrading from < 1.0, please see UPGRADING for migration instructions.
Usage
Object
Parameters:
mixedStr
: The string to separate the JSON from the text.parseToObject
: If set tofalse
, the resulting JSON strings will not be translated to JSON objects. Default istrue
.
Example
Input
var jsonFromText = ;var sampleText = "There was a change from {'animal':'dog', 'color':'blue'} to {'animal':'cat', 'color':'red'}'";var results = ;console;
Output:
Mentions
License
Copyright (c) 2017-2018 Tejas Shah
MIT License, see LICENSE for details.