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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:00:26+00:00 2026-06-08T16:00:26+00:00

I have the below JSON and need to iterate thru the rule object. I

  • 0

I have the below JSON and need to iterate thru the “rule” object. I can never seems to call it correctly to be able access more than just the last rule.

If someone could point me in the right direction, i’d appreciate it

var rules = [{
"rule":[{
    "fields":["CASE.PROSECUTED_FLAG","CASE.RESTITUTION_SIGNED"],
    "conditions":["N","Y"],
    "actions":"required",
    "action_fields":["test1","test2"]
}],
"rule":[{
    "fields":["CASE.PROSECUTED_FLAG","CASE.RESTITUTION_SIGNED"],
    "conditions":["N","N"],
    "actions": "required",
    "action_fields": ["test3", "test4"]
}],
 "rule":[{
    "fields":["CASE.PROSECUTED_FLAG"],
    "conditions":["Y"],
    "actions": "required",
    "action_fields": ["test5"]
}]
}];




function rulesControl() {
    alert(rules.length);
    for (var rule in rules) {

    var xfields = rules[rule].rule.fields;
    var conditions = rules[rule].rule.conditions;
    var actions = rules[rule].rule.actions;
    var action_fields = rules[rule].rule.action_fields;

    //test the fields (if success, mark them, else clear them)
    if (validateRule(xfields, conditions)) {
        rulesAction(actions, action_fields);
    } else {
        ruleActionMakeClear(action_fields);
    }
    }
}
  • 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-08T16:00:27+00:00Added an answer on June 8, 2026 at 4:00 pm

    That is because that JSON is oddly formed. It defines the property “rule” on teh containing object three times, in essence overwriting itself. This is probably more what you are after, rather than having all those single item arrays nested in objects.

    var rules = [
    {"rule":
        {
        "fields":["CASE.PROSECUTED_FLAG","CASE.RESTITUTION_SIGNED"],
        "conditions":["N","Y"],
        "actions":"required",
        "action_fields":["test1","test2"]
        }
    },
    {"rule":
        {
        "fields":["CASE.PROSECUTED_FLAG","CASE.RESTITUTION_SIGNED"],
        "conditions":["N","N"],
        "actions": "required",
        "action_fields": ["test3", "test4"]
        }
    },
    {"rule":
        {
        "fields":["CASE.PROSECUTED_FLAG"],
        "conditions":["Y"],
        "actions": "required",
        "action_fields": ["test5"]
        }
    }
    ];
    

    You would access this as:

    rules[i].rule.PROPERTY
    

    Where i is the index value for the rule and PROPERTY is fields, conditions, etc.

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

Sidebar

Related Questions

I have JSON Object that looks something like the below object, this object can
I have a JSON file which I need to iterate over, as shown below...
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
I have the below Json object in jquery which i m using to fill
I have an example json as below: { Passwd:String content, Userme:String content } how
I have a JSON array like below: var jsonArray = [{k1:v1},{k2:v2},{k3:v3},{k4:v4},{k5:v5}] I don't know
I have a c# object (below) that I'm trying to send to my javascript.
I have a JSON response from a web service that I need to be
I have a JSON file, and i need to extract values from it and
I need to convert a string to a JSON object that gets returned from

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.