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

  • Home
  • SEARCH
  • 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 8917325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:27:29+00:00 2026-06-15T05:27:29+00:00

I have JSON data that is in the format below. I need to get

  • 0

I have JSON data that is in the format below. I need to get the store name corresponding to the one which has specialDeal as true in “Non Veg”. (NOTE: Only one of the stores will have specialDeal as true and also please note the content inside nonVeg is not an array). How will I retrieve it? Please help. Thanks in advance.

{
  "Veg": {
    "amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
    "discntType":"", "Store":"", "StoreType":"", "Fund":"",
    "FundDetails":[
      {"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
      {"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
    ]
  },
  "Non Veg": {
    "chicken":[
      {
        "amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
        "discntType":"", "Store":"", "StoreType":"", "Fund":"",
        "specialDeal":"", "promoStatus":"",
        "FundDetails":[
          {"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
          {"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
        ]
      },
      {
        "amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
        "discntType":"", "Store":"", "StoreType":"", "Fund":"",
        "specialDeal":"", "promoStatus":"",
        "FundDetails":[
          {"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
          {"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
        ]
      }
    ],
    "fish":[
      {
        "amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
        "discntType":"", "Store":"", "StoreType":"", "Fund":"",
        "specialDeal":"", "promoStatus":"",
        "FundDetails":[
          {"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
          {"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
        ]
      },
      {
        "amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
        "discntType":"", "Store":"", "StoreType":"", "Fund":"",
        "specialDeal":"", "promoStatus":"",
        "FundDetails":[
          {"status":"", "discntVal":"", "FundVal":"", "FundBal":""},
          {"status":"", "discntVal":"", "FundVal":"", "FundBal":""}
        ]
      }
    ],
    "egg":[
      {
        "amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
        "discntType":"", "Store":"", "StoreType":"", "Fund":"",
        "specialDeal":"", "promoStatus":"",
        "discntVal":"", "FundVal":"", "FundBal":""
      },
      {
        "amtSpent":"", "shortDesc":"", "longDesc":"", "excTxt":"",
        "discntType":"", "Store":"", "StoreType":"", "Fund":"",
        "specialDeal":"", "promoStatus":"",
        "discntVal":"", "FundVal":"", "FundBal":""
      }
    ]
  },
  "isMember":"Y",
  "orderId":""
}

Here’s the code I’ve tried:

var nonveg = DealsJSON.Non Veg; //where JSON is our json data
for (var key in nonveg) {
    for (var i = 0; i < nonveg[key].length; i++) {
        var amountObj = nonveg[key][i];
        if (amountObj['specialDeal'] == true) {
            console.log(amountObj['Store']);
        }
    }
}
  • 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-15T05:27:30+00:00Added an answer on June 15, 2026 at 5:27 am

    The code looks fine other than:

    var nonveg = DealsJSON.Non Veg;
    

    …which is a syntax error. Property literals can’t have spaces in them, even though property names can. To use a property whose name is not a valid literal, you can use bracketed notation:

    var nonveg = DealsJSON["Non Veg"];
    

    Details: In JavaScript, you can access an object property in two ways:

    1. Dot notation and a literal for the name, e.g. obj.foo.

    2. Bracketed notation and a string for the name, e.g. obj["foo"]. And the string doesn’t have to be just a string literal, it can be the result of any expression.

    Separately, this is suspect:

    if (amountObj['specialDeal'] == true) {
    

    Comparing things to true with == in JavaScript is usually not a good idea. If you just want to know if specialDeal has a value that isn’t 0, false, "", undefined, or null (and it can’t be undefined, JSON doesn’t support that), just remove the comparison:

    if (amountObj['specialDeal']) {
    

    or of course

    if (amountObj.specialDeal) {
    

    Also note that in your JSON, specialDeal is given as a string. If the string is always blank for things that aren’t special deals, that’s fine, because blank strings are falsey. But if the string may contain, for instance, "false", you have to be careful, because the string "false" is not false. We’d have to see an example of other possible values in order to advise you how to deal with that, but if it’s always "" for false and some other string for true, the above is fine.

    If I change your JSON to have a specialDeal that’s true, this code with the mods listed above works fine: Live Example | Source

    var nonveg = DealsJSON["Non Veg"];
    for (var key in nonveg) {
      for (var i = 0; i < nonveg[key].length; i++) {
        var amountObj = nonveg[key][i];
        if (amountObj.specialDeal) {
          display("Found store: " + amountObj.Store);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that contains cached data in JSON format. I'm trying
I have a JSON-like data structure (which I don't want to change) that is
I have some simple data in XML format which I need to convert to
I have some data in JSON format in a text file as below. I
I have some data that I have to serialize to JSON. I'm using JSON.NET.
I have an app that received JSON data from the server. Currently when I
If i have a php file that outputs json data with numerical keys, like
I have a controller that is called with AJAX (sends JSON data), so I
I have a rake task that pulls and parses JSON data over an SSL
I have 2 activities. The first activity is an activity that parses JSON data

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.