Javascript使用stringify neested对象解析JSON

Javascript使用stringify neested对象解析JSON,javascript,json,parsing,nested,Javascript,Json,Parsing,Nested,我试图解析一个应用程序(AWS lambda)在日志文件中编写的json对象,但这个json嵌套了一个stringify对象。诸如此类: input = '{"object":"{\"base\":\"brn\",\"scope\":\"all\",\"channel\":\"sve\",\"service\":\"g

我试图解析一个应用程序(AWS lambda)在日志文件中编写的json对象,但这个json嵌套了一个stringify对象。诸如此类:

input = '{"object":"{\"base\":\"brn\",\"scope\":\"all\",\"channel\":\"sve\",\"service\":\"getAssociatesCards\",\"entity\":\"consolidate\",\"attribute\":\"cRelId\",\"qualifier\":\"45430608\"}"}'
当我试图解析它时失败了:

JSON.parse(input)
出现此错误时:

SyntaxError: Unexpected token b in JSON at position 13

我能做些什么来修复这个问题并获得一个好的Json对象?

如果您可以控制问题代码中类似Json的定义,请使用
String.raw
声明它,这样反斜杠就会被解释为文字反斜杠

内部的
对象
属性包含更多的JSON,因此如果需要,您也可以对其进行解析:

const input=String.raw`{“object”:“{“base\”:“brn\”,“scope\”:“all\”,“channel\”:“sve\”,“service\”:“getAssociatesCards\”,“entity\”:“consolidate\”,“attribute\”:“cRelId\”,“qualifier\:“45430608\”};
const parsed=JSON.parse(输入);

log(JSON.parse(parsed.object))如果您正在从某个日志文件中读取此文件,并且无法控制它的定义方式,则始终可以剥离内部json并自行解析它

var-input='{“object”:“{“base\”:“brn\”,“scope\”:“all\”,“channel\”:“sve\”,“service\”:“getAssociatesCards\”,“entity\”:“consolidate\”,“attribute\”:“cRelId\”,“qualifier\”:“45430608\”});
var innerJSON=input.substring(11,input.length-2);
console.log({
对象:JSON.parse(innerJSON)

});嗨,我无法控制JSON的定义。我从一个文件中读取JSON并试图解析它。