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 8655655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:05:08+00:00 2026-06-12T15:05:08+00:00

Given JSON String/object { selectAll: false, include: { country_197: { id: 197, data_type: country,

  • 0

Given JSON String/object

{
    "selectAll": false,
    "include": {
        "country_197": {
            "id": "197",
            "data_type": "country",
            "name": "Singapore",
            "desc": "",
            "parent_key_id": "all_all",
            "status": ""
        },
        "country_100": {
            "id": "100",
            "data_type": "country",
            "name": "India",
            "desc": "",
            "parent_key_id": "all_all",
            "status": ""
        }
    },
    "exclude": {
        "state_2": {
            "id": "2",
            "data_type": "state",
            "name": "Andhra Pradesh",
            "desc": "",
            "parent_key_id": "country_100",
            "status": ""
        }
    }
}

Given search string is: country_100

Required :
Have to search for country_100 in Given JSON String/object by key parent_key_id
Ex: searching country_100 is found :

{
    "selectAll": false,
    "include": {
        "country_197": {
            "id": "197",
            "data_type": "country",
            "name": "Singapore",
            "desc": "",
            "parent_key_id": "all_all",
            "status": ""
        },
        "country_100": {
            "id": "100",
            "data_type": "country",
            "name": "India",
            "desc": "",
            "parent_key_id": "all_all",
            "status": ""
        }
    },
    "exclude": {
        "state_2": {
            "id": "2",
            "data_type": "state",
            "name": "Andhra Pradesh",
            "desc": "",
            "parent_key_id": "**country_100**",
            "status": ""
        }
    }
}

So return True, else return false.
This is what I have so far

var id = 'country_100', found = false;
for (var i=0; i<data.length; i++) { 
    console.log(data[i].exclude['state_2'].parent_key_id); 
    if (data[i].exclude['state_2'].parent_key_id == id) { 
        found = true; 
        break; 
    }
}
  • 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-06-12T15:05:09+00:00Added an answer on June 12, 2026 at 3:05 pm

    Here ya go!
    http://jsfiddle.net/8p9KF/

    <script type="text/javascript">
    onerror=function(a,b,c){alert([a,b,c])};
    </script>
    <script type="text/javascript">
    var myJSON={
      "selectAll":false,
      "include":
      {
        "country_197":{"id":"197","data_type":"country","name":"Singapore","parent_key_id":"all_all"},
        "country_100":{"id":"100","data_type":"country","name":"India","parent_key_id":"all_all"}
      },
      "exclude":
      {"state_2":
        {"id":"2","data_type":"state","name":"Andhra Pradesh","parent_key_id":"country_100"}
      }
    };
    
    //alert(myJSON.include["country_100"].data_type=="country");
    
    function countryIsIncluded(country)
    {
        var keyExists=(country in myJSON.include);
        if(!keyExists)return false;
        return (myJSON.include[country].data_type=="country");
    }
    
    function countryIsExcluded(country)
    {
        var keyExists=(country in myJSON.exclude);
        if(!keyExists)return false;
        return myJSON.exclude[country].data_type=="country";
    }
    
    function stateIsIncluded(state)
    {
        var keyExists=(state in myJSON.include);
        if(!keyExists)return false;
        return myJSON.include[state].data_type=="state";
    }
    
    function stateIsExcluded(state)
    {
        var keyExists=(state in myJSON.exclude);
        if(!keyExists)return false;
        return myJSON.exclude[state].data_type=="state";
    }
    
    countryIdMap={};
    stateIdMap={};
    for(var j in myJSON.include){
     if(!myJSON.include.hasOwnProperty(j))continue;
     if(myJSON.include[j].data_type=="country")countryIdMap[myJSON.include[j].name]=myJSON.include[j].id;
     else if(myJSON.include[j].data_type=="state")stateIdMap[myJSON.include[j].name]=myJSON.include[j].id;
    }
    for(var j in myJSON.exclude){
     if(!myJSON.exclude.hasOwnProperty(j))continue;
     if(myJSON.exclude[j].data_type=="country")countryIdMap[myJSON.exclude[j].name]=myJSON.exclude[j].id;
     else if(myJSON.exclude[j].data_type=="state")stateIdMap[myJSON.exclude[j].name]=myJSON.exclude[j].id;
    }
    
    
    function lookUpCountry(countryName)
    {
        var c=(countryName in countryIdMap)?"country_"+countryIdMap[countryName]:countryName;
        return {included:countryIsIncluded(c),excluded:countryIsExcluded(c)};
    }
    
    function lookUpState(stateName)
    {
        var s=(stateName in stateIdMap)?"state_"+stateIdMap[stateName]:stateName;
        return {included:stateIsIncluded(s),excluded:stateIsExcluded(s)};
    }
    
    
    var india=lookUpCountry("India");
    alert("India is:\nincluded: "+(india.included?"Y":"N")+"\nexcluded: "+(india.excluded?"Y":"N"));
    
    var country_100=lookUpCountry("country_100");
    alert("country_100 is:\nincluded: "+(country_100.included?"Y":"N")+"\nexcluded: "+(country_100.excluded?"Y":"N"));
    
    var country_197=lookUpCountry("country_197");
    alert("country_197 is:\nincluded: "+(country_197.included?"Y":"N")+"\nexcluded: "+(country_197.excluded?"Y":"N"));
    
    var country_349999=lookUpCountry("country_349999");
    alert("country_349999 is:\nincluded: "+(country_349999.included?"Y":"N")+"\nexcluded: "+(country_349999.excluded?"Y":"N"));
    
    var state_2=lookUpState("state_2");
    alert("state_2 is:\nincluded: "+(state_2.included?"Y":"N")+"\nexcluded: "+(state_2.excluded?"Y":"N"));
    
    var andhraPradesh=lookUpState("Andhra Pradesh");
    alert("Andhra Pradesh is:\nincluded: "+(andhraPradesh.included?"Y":"N")+"\nexcluded: "+(andhraPradesh.excluded?"Y":"N"));
    
    var state_2999=lookUpState("state_2999");
    alert("state_2999 is:\nincluded: "+(state_2999.included?"Y":"N")+"\nexcluded: "+(state_2999.excluded?"Y":"N"));
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this JSON string: { success:true,user_id:309,id:309,sessId:false,email:null,name:Mai Van Quan,username:quanmv,role:Reseller Admin,messages:,org_name:null,microPayNumber:4949,microPayWord:neocam,mobile:null,permissions:{ADD_CAMERA:true, REMOVE_CAMERA:true, EDIT_CAM_GENERAL:true, ACCESS_CAM_TECHNICAL:true, EDIT_CAM_PKG:true,
I have parsed a given CSS file/string into a JSON object like so: {
Given the following array of json objects: var items = [ {id:1, parentId:0, name:'item1'},
I need to create an array or an object from a given string. String
I have a JSON string and I'd like to use to compose an object.
I have a JSON object consisting of strings for the name and arrays for
I want to parse a JSON object and create a JSONEvent with the given
Given a string of JSON data, how can I safely turn that string into
Apparently jQuery has the ability to decode a given object or string into a
I'd like to be able to parse a string of JSON representing an object

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.