Chat on WhatsApp

Building a Dynamic Offline Survey Application with a JSON Rule Engine

Dipen Patel

Dipen Patel

views 431

Views

Building a Dynamic Offline Survey Application with a JSON Rule Engine

Table of Contents

Toggle TOC

Collecting accurate data in the field often means dealing with poor or completely absent internet connectivity. At the same time, modern surveys rely heavily on conditional logic – questions that appear or disappear depending on prior responses. We needed a solution that could deliver both: 100% offline capability and complex, rule-based dynamic survey flows.

To meet this challenge, we built a powerful yet lightweight iOS application (designed primarily for iPads) that uses a JSON-driven rule engine to control survey behavior entirely on the device.

The Challenge

Field researchers frequently operate in locations where:

  • Network availability is inconsistent
  • Surveys require multi-level conditional logic
  • Responses must be validated instantly
  • Large-scale questionnaires must remain maintainable

Traditional survey platforms struggle in these conditions. Our goal was to build an app that works anywhere, supports advanced branching logic, and ensures high-quality data at the point of collection.

Our Solution: A JSON-Powered Offline Survey Application

As a mobile app development company experienced in offline-first architectures, we created an iOS app that stores all survey data locally and uses a custom JSON rule engine to drive question flow.

  • Smooth operation with zero connectivity
  • Real-time logic execution
  • Instant validation and error alerts
  • Fully customizable surveys without changing the application code

Architecture Overview

1. The Rule Engine

At the heart of our system is a lightweight rule engine designed to evaluate boolean expressions. It reads JSON configurations and determines:

  • Which question to show
  • Which to skip
  • When to trigger validations and alerts

The engine executes these rules dynamically and instantly, enabling seamless branching logic throughout the survey.

2. Question Structure

Each question follows a simple and intuitive JSON-based design:

  1. Question content – text, input type, UI behavior
  2. Conditions array – rules determining if the question should be shown
  3. Processes – post-answer actions for:
    • Data reporting
    • Smart validation and alerts

This structure is deliberately minimal, making it easy to maintain even for non-technical survey designers.

Conditional Logic Made Simple

The conditions system supports two logical combinations:

  • All conditions (AND logic) – every condition must be true
  • Any conditions (OR logic) – at least one condition must be true

When the surveyor reaches a question:

  1. The engine evaluates its conditions
  2. If true, the question appears
  3. If false, the question is skipped
  4. The engine advances to the next question automatically

This approach supports complex skip patterns and ensures a natural, context-aware flow.

Smart Data Validation

To improve data accuracy, the application runs a dual-process validation pipeline after every answer.

1. Reporting Process

This process assigns values to internal identifiers – what we call bank codes.
These stored values can then be referenced by future conditions, enabling multi-step dynamic logic.

2. Alerting Process

The app actively checks for unusual responses and immediately prompts the surveyor to reassess.

Examples of alerts include:

  • A household marked with 0 bathrooms
  • A residential home with no kitchen
  • Responses falling outside expected real-world ranges

This real-time feedback helps prevent errors before the data even leaves the field.

Why This Approach Works

✔ Simplicity

The array-based JSON structure is easy to understand, modify, and visualize—no complex flowchart tools needed.

✔ Flexibility

Boolean expressions enable highly advanced survey logic while remaining lightweight and fast.

✔ Reliability

Because everything is stored and processed locally, the app works flawlessly even without internet access.

✔ Data Quality

Immediate alerts catch inaccurate entries at the moment they occur, dramatically improving overall data integrity.

Technical Implementation

  • Language: Swift
  • Platform: iOS (iPad-optimized)
  • Storage: Local database for offline operation
  • Logic: JSON-based rule engine fully separate from application code

Survey logic updates require no app update – just replace the JSON configuration.

Managing Large-Scale Surveys (600+ Questions)

When our survey expanded to nearly 600 questions, a single JSON file became impossible to maintain. Updating or testing such a large configuration was inefficient and error-prone.

Our Solution: Modular JSON Architecture

We broke the survey into multiple logical sections, each in its own JSON file:

  • demographics.json
  • household_characteristics.json
  • amenities.json
  • economic_activities.json and more

Benefits of Modularization

1. Section-Level Testing

Each section could be validated independently.
If we changed the demographics section, we only retested those ~50 questions, not the entire survey.

2. Collaboration-Friendly

Multiple team members could work on different sections without conflicts.

3. Safe Updates

Changes to one file couldn’t accidentally break logic in another section.

4. Meaningful Version Control

Git diffs became clear and focused:
Instead of “600 lines changed,” we saw “demographics updated with new age brackets.”

Deployment Process

Before deploying to field devices, we built an automated process to ensure quality.

Our build script:

  1. Validates each JSON section for syntax and schema accuracy
  2. Runs automated logic tests on conditions within each section
  3. Combines all sections into a single master survey JSON
  4. Bundles the final configuration with the iOS app

This approach gives us modular development with unified runtime behavior – the best of both worlds.

Conclusion

This project demonstrates that complex, dynamic surveys don’t require cloud dependence or heavy infrastructure. By combining:

  • A clean, JSON-driven rule engine
  • Local data storage
  • Modular survey design
  • Smart real-time validation

We created a reliable survey application that works anywhere – offline, online, urban, or remote.

Related Blogs

Bhargav Simejiya

Bhargav Simejiya

How to Make Money From App

Millions of apps are available on app stores today, but only a small percentage generate meaningful revenue. Many app creators spend months developing an app only to realize they have no clear monetization strategy. Others believe they need millions of...

Read More Arrow
How to Make Money From App Mobile Application
Bhargav Simejiya

Bhargav Simejiya

Banking App Development Cost & Security Features

Banking app projects usually begin with a simple goal: give customers a better digital experience. A few workshops later, the conversation tends to look very different. Product teams start discussing customer onboarding. Compliance teams raise concerns about KYC requirements. Security...

Read More Arrow
Banking App Development Cost & Security Features Mobile Application
Bhargav Simejiya

Bhargav Simejiya

How to Launch an App in the USA Successfully

What Does It Mean to Successfully Launch an App in the USA? A successful app launch in the USA means achieving measurable user acquisition, strong Day-7 and Day-30 retention rates, positive App Store or Google Play rankings, and sustainable organic...

Read More Arrow
How to Launch an App in the USA Successfully Mobile Application
Mitul Patel

Mitul Patel

Overcoming the Challenges of Implementing BLE Smart Lock Technology with Multi-Layer Security

We started with a BLE integration task.We ended up reverse-engineering an encrypted security protocol. Kerong’s BLE smart locks operate nothing like consumer Bluetooth devices. Why? Because beneath the BLE layer sits a multi-stage security architecture. It involves many security nuances...

Read More Arrow
Overcoming the Challenges of Implementing BLE Smart Lock Technology with Multi-Layer Security IoT app development
Bhargav Simejiya

Bhargav Simejiya

Mobile App Development Cost in USA

Mobile App Development Cost in USA: What Does It Really Cost to Build an App? One software company quotes $30,000 for your app idea. Another proposes a budget of $75,000. A third estimates more than $150,000. For many business owners,...

Read More Arrow
Mobile App Development Cost in USA Mobile Application
Dhaval Baldha

Dhaval Baldha

Building Reliable Large-File Uploads for Mobile Apps Using Chunking

Uploading large videos from mobile devices is a common requirement in modern apps - social platforms, e-commerce, education, streaming, and professional tools all rely on reliable media uploads. However, achieving a smooth and stable upload experience on mobile networks is...

Read More Arrow
Building Reliable Large-File Uploads for Mobile Apps Using Chunking Mobile Application

Book a consultation Today

Feel free to call or visit us anytime; we strive to respond to all inquiries within 24 hours.


    Upload file types: PDF, DOC, Excel, JPEG, PNG, WEBP File size:10 MB

    btn-arrow

    consultation-img