I am already trying for over an hour and cant figure out the right way to do it. I have this Regex:
const search = /("Response)\s+\d+\s+(of)\s+\d+(":)\s+/g;
I have this string:
{"Response 1 of 2": {"Name": "Jouny", "Class": "TR23", "Message Type": "Offer", "ID Identifier": "19256", "Address": "hjfhfgjhjhj"}, "Response 2 of 2": {"Name": "Sarah", "Class": "BHT56", "Message Type": "Alarm", "ID Identifier": "89756767", "Address": "oplkdhdggd"}}
I would like to have a result like this:
[
{"Name": "Jouny", "Class": "TR23", "Message Type": "Offer", "ID Identifier": "19256",
"Address": "hjfhfgjhjhj"},
{"Name": "Sarah", "Class": "BHT56", "Message Type": "Alarm", "ID Identifier": "89756767",
"Address": "oplkdhdggd"}
]
my code:
var lines = results.toString().split(/\n/);
lines.forEach(function (item) {
if (item.indexOf(myData) > 0) {
var json = item.slice(item.indexOf(script) + script.length + 2).replace(PRINTABLE_CHAR, '');
var jsonMatch = json.split(json.match(search));
var result = jsonMatch.substr(0, jsonMatch.lastIndexOf('}')).replace(PRINTABLE_CHAR, '');
try {
data = JSON.parse(result);
} catch (e) {
console.log('ERROR');
}
}
});