1

I'm converting a xml file to a Json format, I'm trying to query the Json using linq.js so far this is what I've done:

var queryResult  = linq.from(result).where( function(x){ return x.key == "bpmn2:definitions"   } ).select(function(x)  {  return x } ).toArray();

and I get the following json:

[ { key: 'bpmn2:definitions',
    value:
     { '$': [Object],
       'bpmn2:message': [Object],
       'bpmn2:interface': [Object],
       process: [Object] } } ]

how can I get in the same query just by modifying the where clause the embedded object named Process?

EDIT:

I've made it so far:

var queryResult  = linq.from(result).where( function(x){ return x.key == "bpmn2:definitions"   } ).select(function(x)  {  return x.value.process } ).toArray();

and I get

[ [ { '$': [Object],
      'bpmn2:process': [Object],
      'bpmndi:BPMNDiagram': [Object] } ] ]

how can I access bpmn2:process within the same query described above?

thanks for the help

pedrommuller
  • 15,741
  • 10
  • 76
  • 126

1 Answers1

1

Like this? I think this is what you're asking.

var queryResult  = linq.from(result).where( function(x){ return x.key == "bpmn2:definitions"   } ).select(function(x)  {  return x.value.process } ).toArray();
000
  • 26,951
  • 10
  • 71
  • 101
  • thanks Joe, I just got into the same result a minute ago, thanks for the answer that's correct if you can take a look I edited the question I'm trying to elaborate a more complex query, sorry for the edit – pedrommuller Apr 04 '14 at 14:24
  • 1
    I did it this way I feels a little bit dirty to me: linq.from(result).where( function(x){ return x.key == "bpmn2:definitions" } ).select(function(x) { return x.value.process[0]["bpmn2:process"] } ).toArray(); anyway it works! thanks for the help – pedrommuller Apr 04 '14 at 14:30
  • 1
    @Pedro just as a sidenote. I would not use x.key == "bpmn2:definitions" because for every comparison you do a typecast. Use the strict equality comparer "===" not "==". The "==" is only good to use when you compare an integer like 2 and yo do not care wether 2 is also a "2". See http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons – Pascal May 05 '14 at 18:11