Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6135913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:32:16+00:00 2026-05-23T17:32:16+00:00

I have some JSON that looks like: groups: [ group_id: 8, group_name: Building, group_color:

  • 0

I have some JSON that looks like:

"groups": [

  "group_id": "8",
  "group_name": "Building",
  "group_color": "00ff00"
},
{
  "group_id": "3",
  "group_name": "Building",
  "group_color": "8000ff"
},
{
  "group_id": "2",
  "group_name": "Sidewalk",
  "group_color": "ff0000"
},
{
  "group_id": "6",
  "group_name": "Parking Lot",
  "group_color": "00ffff"
},
{
  "group_id": "3",
  "group_name": "Commons",
  "group_color": "ff8000"
},
{
  "group_id": "5",
  "group_name": "Other",
  "group_color": "ff00ff"
}
]

And when a field is found it flips a boolean flag.
e.g.

for (var c=0; c<json.groups.length; c++) {
   inSearch = false;
   if(json.groups.group_id.match(query)!=null){
      inSearch = true;
   }
}

However, if query = Building then I return two results, so what I’m looking to do is set query = Building&8 to return only the first result.

Note: query can also be a regular expression which I think is where this should go…

Any ideas?

EDIT: Is there a way to, say, split my string into parts and then match a single object based on two different pieces of that object? So match the first object based on either group_id and group_color, or match it based on group_name and group_color?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:32:17+00:00Added an answer on May 23, 2026 at 5:32 pm

    For present case something like this should work:

    data = JSON.parse('your_json');
    for (var i=0, j=data.length; i<j; i++){
        var inSearh = false;
        if(data[i].group_id===8 && data[i].group_name==="Something"){
        inSearch = true;
        break;
        }
    }
    

    For a more general case you can wrap it in a function:

    key_tester = function(jsonData,key1, value1, key2, value2){
        // Here jsonData is parsed JSON
        for(var i=0, j=jsonData.length; i<j; i++){
            var obj = jsonData[i];
            if(obj[key1] == value1 && obj[key2] == value2){
                return true; 
         }
         return false;
    }
    

    Then you can use it like:

    jsonData = JSON.parse('Your json');
    if (key_tester(jsonData, "group_id","8","group_name","building"))
       // Here goes your awesome code
    

    You can extend the key_tester function to include more key value pairs.

    This should save us from going the regex way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside my .aspx I have some JSON code that looks like this: function someFunctionName()
I have some JSON data that looks like this: { 910719: { id: 910719,
Greetings all, I have some JSON code that looks like this: { playlist: [
I have some code that looks like this: NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions
I have some JSON that looks like this: { ST: Security, C1: Login failures,
I have some JSON data that looks like this: { data: [{ name:John Smith,
I have some JSON I am parsing that looks like this: { dhkplhfnhceodhffomolpfigojocbpcb: {
I have some JSON that is sent to my webservice that looks something like
I have some JSON which looks generally like this... {appJSON: [ { title:Application Title,
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.