Chat on WhatsApp

Building a Dynamic Offline Survey Application with a JSON Rule Engine

Dipen Patel

Dipen Patel

views 6 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

Chirag Solanki

Chirag Solanki

Mobile + Headless CMS: A Scalable Component-Driven Approach

Building mobile apps that scale is no longer just about performance, it's about flexibility, maintainability, and how quickly teams can deliver new experiences without rewriting code. Recently, we faced a real-world challenge that pushed us to rethink how mobile apps...

Read More Arrow
Mobile + Headless CMS: A Scalable Component-Driven Approach Mobile Application
Yash Shah

Yash Shah

How to Troubleshoot Android Game Publishing Issues: A Step-by-Step Guide

3.9 million apps and counting! The world’s largest app store, The Google Play Store, is an obvious choice of developers and entrepreneurs for publishing their Android apps. However, it is not easy to publish Android app on Play Store because...

Read More Arrow
How to Troubleshoot Android Game Publishing Issues: A Step-by-Step Guide Games/AR/VR
Bhargav Simejiya

Bhargav Simejiya

Integrating IoT with Mobile Applications for Real-Time Monitoring

In the modern hyper-connected digital world, the Internet of Things (IoT) is changing the relationship between technology and consumers as well as companies. The IoT integration for mobile apps is the future because of the fast-growing healthcare wearables, building automation systems, and...

Read More Arrow
Integrating IoT with Mobile Applications for Real-Time Monitoring Mobile Application
Bhargav Simejiya

Bhargav Simejiya

Navigating the Hurdles: Expert Solutions for Common Mobile App Development Issues

Mobile app development in 2025 presents a lucrative opportunity for businesses to connect with their audience and streamline operations. However, the journey from concept to a successful app launch is often fraught with mobile app development challenges. From the complexities...

Read More Arrow
Navigating the Hurdles: Expert Solutions for Common Mobile App Development Issues App Solutions
Mitul Patel

Mitul Patel

Build a Language Learning App Like Duolingo: Full 8-Step Guide

Language learning apps like Duolingo have transformed how millions acquire new languages, combining gamification, accessibility, and bite-sized lessons to make learning engaging. Building a similar app requires careful planning, technical expertise, and a user-centric approach. In this 8-step guide, we’ll...

Read More Arrow
Build a Language Learning App Like Duolingo: Full 8-Step Guide Mobile Application
Dhaval Baldha

Dhaval Baldha

React Native vs Ionic : Which Cross-Platform Framework Is Better?

Cross-platform mobile app development allows businesses to target both iOS and Android with a single codebase, saving time and resources. Two leading frameworks, Ionic and React Native, are popular choices for building cross-platform apps. But which one suits your project...

Read More Arrow
React Native vs Ionic : Which Cross-Platform Framework Is Better? 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