Javascript 在嵌套json对象的深处查找对象

Javascript 在嵌套json对象的深处查找对象,javascript,json,object,lodash,Javascript,Json,Object,Lodash,我在下面的代码段中有嵌套的json对象,希望找到所有出现的“$schema”,并将包含该schema值的整个对象保存到另一个对象中。我尝试使用lodash过滤器,但没有成功。有人有什么建议吗 { “元素”:“解析结果”, “内容”:[ { “元素”:“类别”, “元”:{ “类别”:[ “api” ], “标题”:“测试” }, “属性”:{ “元”:[ { “元素”:“成员”, “元”:{ “类别”:[ “用户” ] }, “内容”:{ “关键”:{ “元素”:“字符串”, “内容”:“格式

我在下面的代码段中有嵌套的json对象,希望找到所有出现的“$schema”,并将包含该schema值的整个对象保存到另一个对象中。我尝试使用lodash过滤器,但没有成功。有人有什么建议吗

{
“元素”:“解析结果”,
“内容”:[
{
“元素”:“类别”,
“元”:{
“类别”:[
“api”
],
“标题”:“测试”
},
“属性”:{
“元”:[
{
“元素”:“成员”,
“元”:{
“类别”:[
“用户”
]
},
“内容”:{
“关键”:{
“元素”:“字符串”,
“内容”:“格式”
},
“价值”:{
“元素”:“字符串”,
“内容”:“1A”
}
}
}
]
},
“内容”:[
{
“元素”:“类别”,
“元”:{
“类别”:[
“资源组”
],
“标题”:“问题”
},
“内容”:[
{
“元素”:“资源”,
“元”:{
“标题”:“问题”
},
“属性”:{
“href”:“/问题”
},
“内容”:[
{
“元素”:“转换”,
“元”:{
“标题”:“列出所有问题”
},
“内容”:[
{
“元素”:“httpTransaction”,
“内容”:[
{
“元素”:“httpRequest”,
“属性”:{
“方法”:“获取”
},
“内容”:[]
},
{
“元素”:“httpResponse”,
“属性”:{
“状态代码”:“200”,
“标题”:{
“元素”:“httpHeaders”,
“内容”:[
{
“元素”:“成员”,
“内容”:{
“关键”:{
“元素”:“字符串”,
“内容”:“内容类型”
},
“价值”:{
“元素”:“字符串”,
“内容”:“应用程序/json”
}
}
}
]
}
},
“内容”:[
{
“元素”:“数据结构”,
“内容”:[
{
“元素”:“问题列表”
}
]
},
{
“要素”:“资产”,
“元”:{
“类别”:[
“消息体”
]
},
“属性”:{
“contentType”:“应用程序/json”
},
“内容”:“[\n{\n\'question\\”:“最喜爱的编程语言”;\n\'published\\”:“2014-11-11T08:40:51.620Z\”,\n\'url\':“/questions/1\”,\n\'choices\”:[\n{\n\'choice\':“Javascript\”,\n\'url\':“:“/questions/1/choices/1\”,\n\'vows\”:2048\n\n\n
},
{
“要素”:“资产”,
“元”:{
“类别”:[
“messageBodySchema”
]
},
“属性”:{
“contentType”:“应用程序/架构+json”
},
“内容”:“{\n\”$schema\”:\”http://json-schema.org/draft-04/schema#\“,\n\”类型\“:\”数组\“\n}”
}
]
}
]
}
]
}
]
},
{
“元素”:“资源”,
“元”:{
“标题”:“问题”
},
“属性”:{
“href”:“/questions/{id}”,
“hrefVariables”:{
“元素”:“hrefVariables”,
“内容”:[
{
“元素”:“成员”,
“属性”:{
“类型属性”:[
“必需”
]
},
“内容”:{
“关键”:{
“元素”:“字符串”,
“内容”:“id”
},
“价值”:{
“元素”:“编号”,
“内容”:1234
}
}
}
]
}
},
“内容”:[
{
var obj = { "my property": "my value" };
var val = obj["my property"] // "my value";
var obj = { "foo" : "{ \"bar\" : \"my value\" }" } // notice I had to escape the strings with backslashes \
var val = obj.foo.bar // error because foo is a string with the value "{ "bar" : "my value" }"
"content": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"array\"\n}"
"content": { "$schema": "http://json-schema.org/draft-04/schema#", "type": "array" }
function deepParseObject(theObject) {
  for(var prop in theObject) {
      if(typeof theObject[prop] === "string" && (theObject[prop].indexOf('{') == 0 || theObject[prop].indexOf('[') == 0)) {
          theObject[prop] = JSON.parse(theObject[prop]);
      }
      if(theObject[prop] instanceof Object || theObject[prop] instanceof Array)
          deepParseObject(theObject[prop]);
  }
}