• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

Challenges with dojox.json.query

I have the following complex object and I am trying to learn how to query it with dojox.json.query.  
Here is the code and a simple query to find the company.state...can anyone tell me what I am doing wrong?  

This works with simple structures but not this more complex one.


NOTE: I have tried all of these queries with no results returned:

var query = "?Tables.Company.state='UT'";
var query = "?Company.state='UT'";
var query = "?state='UT'";


dojo.require("dojox.json.query");

function mwInit(args) {

    var DataSet = 
{
  "Tables": [
    {
      "Company": [
        {
	      "name": "Company One",
          "address_line_1": "1160 East 3900 South",
          "address_line_2": "Suite 5000",
          "city": "Salt Lake City",
          "state": "UT"
        },
        {
	      "name": "Company two",
          "address_line_1": "1160 East 3900 South",
          "address_line_2": "Suite 5000",
          "city": "Salt Lake City",
          "state": "UT"
        }
      ]
    },
    {
      "Contact": [
        {
          "address_line_1": "123 Main Street",
          "address_line_2": "Suite 500",
          "age": 44,
          "first_name": "John",
          "last_name": "Aarons",
          "state": "UT"
        },
	    {
          "address_line_1": "1160 East 3900 South",
          "address_line_2": "Suite 500",
          "age": 55,
          "first_name": "Bill",
          "last_name": "Jones",
          "state": "UT"
	    },
        {
          "address_line_1": "1160 East 3900 South",
          "address_line_2": "Suite 500",
          "age": 33,
          "first_name": "Sally",
          "last_name": "Smith",
          "state": "UT"
	    }
      ]
  },
  {
      "Action_plan": [
        {
            "call_back_date": "\/Date(1299308400000-0700)\/",
            "detailed_plan": "Do this that and the other"
        },
        {
            "call_back_date": null,
            "detailed_plan": null
        },
        {
            "call_back_date": "\/Date(1300082400000-0600)\/",
            "detailed_plan": "Introduce Hospitalist"
        }
      ]
  }

]
};

var query = "?Tables.Company.state='UT'";

var results = dojox.json.query(query, DataSet);

}

Open in new window

0
marketware
Asked:
marketware
  • 3
1 Solution
 
leakim971PluritechnicianCommented:
For example :
    var query = "?Tables.Company.state='UT'";
    var results = dojox.json.query("$.Tables[0].Company[?state='UT']", DataSet);

Open in new window


Test page : http://jsfiddle.net/kugEF/
0
 
marketwareAuthor Commented:
Yes this works. THANKS!  

Is there a way to make it more simple?

I'd have to know which table # goes with which table, instead of just using the tablename. i.e.,

$Tables[0].Company[?state = 'UT']
$Tables[1].Contact[?last_name = 'Smith']
$Tables[2].Action_plan[?detailed= 'This and that']

Which in my case may change all the time, and or if the tables get returned in a different order then I couldn't hard code any numbers to tables either.

Thanks!!!

bob
0
 
marketwareAuthor Commented:
I figured it out, but you got me on the right path.

The final answer is to run two queries (unless you can show me a shortcut):

var results = dojox.json.query("..[=Contact]", DataSet);
var results2 = dojox.json.query("..[?last_name='Aarons']", results);
0
 
marketwareAuthor Commented:
This answer helped me to see how to find what I needed.  Thanks!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now