Bird
Raised Fist0
Firebasecloud~20 mins

JSON tree structure in Firebase - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Firebase JSON Tree Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
Understanding Firebase JSON Tree Structure Output
Given the Firebase Realtime Database JSON tree below, what is the value returned when querying the path /users/user1/age?
Firebase
{
  "users": {
    "user1": {
      "name": "Alice",
      "age": 30,
      "active": true
    },
    "user2": {
      "name": "Bob",
      "age": 25,
      "active": false
    }
  }
}
A"Alice"
Btrue
C30
Dnull
Attempts:
2 left
💡 Hint
Look at the path and find the value stored under 'age' for 'user1'.
❓ Architecture
intermediate
2:30remaining
Firebase JSON Tree Structure and Data Nesting
Which of the following JSON structures best represents a Firebase Realtime Database tree optimized to avoid deeply nested data for storing blog posts and their comments?
A
{
  "posts": {
    "post1": {
      "title": "Hello"
    }
  },
  "comments": {
    "post1": {
      "comment1": "Nice post!",
      "comment2": "Thanks for sharing"
    }
  }
}
B
{
  "posts": {
    "post1": {
      "title": "Hello",
      "comments": [
        "Nice post!",
        "Thanks for sharing"
      ]
    }
  }
}
C
{
  "posts": {
    "post1": {
      "title": "Hello",
      "comments": {
        "comment1": "Nice post!",
        "comment2": "Thanks for sharing"
      }
    }
  }
}
D
{
  "posts": {
    "post1": {
      "title": "Hello",
      "comments": "Nice post!"
    }
  }
}
Attempts:
2 left
💡 Hint
Firebase recommends flattening data to avoid deep nesting.
❓ security
advanced
3:00remaining
Firebase JSON Tree Security Rules Impact
Given the Firebase Realtime Database JSON tree below, which security rule will allow only authenticated users to read their own profile data under /users/{userId} but deny access to others?
Firebase
{
  "users": {
    "user1": {"name": "Alice"},
    "user2": {"name": "Bob"}
  }
}
A
{
  "rules": {
    "users": {
      "$userId": {
        ".read": "auth != null",
        ".write": "auth != null"
      }
    }
  }
}
B
{
  "rules": {
    "users": {
      "$userId": {
        ".read": "auth != null && auth.uid == $userId",
        ".write": "auth != null && auth.uid == $userId"
      }
    }
  }
}
C
{
  "rules": {
    "users": {
      ".read": "auth != null",
      ".write": "auth != null"
    }
  }
}
D
{
  "rules": {
    "users": {
      "$userId": {
        ".read": "true",
        ".write": "auth != null && auth.uid == $userId"
      }
    }
  }
}
Attempts:
2 left
💡 Hint
Check the condition that matches the authenticated user's ID to the data path.
❓ Configuration
advanced
2:30remaining
Firebase JSON Tree Update Behavior
If you perform an update operation on the Firebase Realtime Database path /users/user1 with the JSON {"age": 31}, what will be the resulting JSON subtree under /users/user1 given the initial data below?
Firebase
{
  "users": {
    "user1": {
      "name": "Alice",
      "age": 30,
      "active": true
    }
  }
}
A
{
  "name": "Alice",
  "age": 31,
  "active": true
}
B
{
  "age": 31
}
C
{
  "name": "Alice",
  "age": 30,
  "active": true
}
D
{
  "name": "Alice",
  "active": true
}
Attempts:
2 left
💡 Hint
Firebase update merges keys, it does not replace the entire node.
🧠 Conceptual
expert
3:00remaining
Analyzing Firebase JSON Tree Data Consistency
Consider a Firebase Realtime Database JSON tree where user profiles and their posts are stored separately as below. If a user deletes their profile, what is the best approach to ensure no orphan posts remain in the database?
Firebase
{
  "users": {
    "user1": {"name": "Alice"}
  },
  "posts": {
    "post1": {"author": "user1", "content": "Hello"},
    "post2": {"author": "user1", "content": "World"}
  }
}
ANo action needed; orphan posts do not affect database consistency.
BManually delete posts before deleting the user profile to avoid orphan posts.
CRely on Firebase Realtime Database rules to automatically delete posts when user is deleted.
DUse Firebase Cloud Functions to trigger on user deletion and remove all posts with matching author ID.
Attempts:
2 left
💡 Hint
Think about automating cleanup to maintain data integrity.

Practice

(1/5)
1. What does a JSON tree structure in Firebase mainly represent?
{"users": {"user1": {"name": "Anna"}}}
easy
A. A way to organize data with keys and nested objects
B. A list of unrelated values
C. A flat file with no hierarchy
D. A method to store images only

Solution

  1. Step 1: Understand JSON structure

    JSON uses keys and values, where values can be objects, creating a tree-like hierarchy.
  2. Step 2: Relate to Firebase data

    Firebase stores data as nested objects, allowing easy access and organization.
  3. Final Answer:

    A way to organize data with keys and nested objects -> Option A
  4. Quick Check:

    JSON tree = nested keys and objects [OK]
Hint: JSON tree means nested keys and objects [OK]
Common Mistakes:
  • Thinking JSON is just a list
  • Confusing flat files with JSON trees
  • Assuming JSON stores only simple values
2. Which of the following is the correct JSON syntax for a Firebase data node representing a user with a name and age?
easy
A. {"user": "name": "John", "age": 30}
B. {"user": {"name": "John", "age": 30}}
C. {"user": ["name": "John", "age": 30]}
D. {"user": ("name": "John", "age": 30)}

Solution

  1. Step 1: Identify valid JSON syntax

    JSON objects use curly braces {} with key-value pairs separated by commas, keys and strings in double quotes.
  2. Step 2: Check each option

    Syntax errors like misplaced colons after string values, parentheses instead of braces, or square brackets with colons are invalid. Only nested curly braces with proper quotes and structure is valid: {"user": {"name": "John", "age": 30}}.
  3. Final Answer:

    {"user": {"name": "John", "age": 30}} -> Option B
  4. Quick Check:

    Valid JSON uses braces and quotes [OK]
Hint: JSON objects use braces {} and quotes "" [OK]
Common Mistakes:
  • Using parentheses instead of braces
  • Using brackets for objects
  • Missing braces around nested objects
3. Given this Firebase JSON data:
{"posts": {"post1": {"title": "Hello"}, "post2": {"title": "World"}}}

What is the value of posts.post2.title?
medium
A. "Hello"
B. post2
C. "World"
D. null

Solution

  1. Step 1: Locate the key path

    posts is the root object, post2 is a child key, and title is inside post2.
  2. Step 2: Read the value at posts.post2.title

    The value is "World" as shown in the JSON.
  3. Final Answer:

    "World" -> Option C
  4. Quick Check:

    posts.post2.title = "World" [OK]
Hint: Follow keys step-by-step to find value [OK]
Common Mistakes:
  • Confusing post1 and post2
  • Reading key names as values
  • Assuming null for missing keys
4. Identify the error in this Firebase JSON snippet:
{"users": {"user1": {"name": "Alice", "age": 25}, "user2": {"name": "Bob", "age": "thirty"}}
medium
A. Age value for user2 should be a number, not a string
B. Comma missing between user1 and user2
C. Keys must not be in quotes
D. Missing closing brace for the root object

Solution

  1. Step 1: Check JSON braces

    The snippet opens four braces but closes only three, missing one closing brace for the root.
  2. Step 2: Validate other parts

    Age as string is allowed in JSON; keys must be in quotes; comma between user1 and user2 is present.
  3. Final Answer:

    Missing closing brace for the root object -> Option D
  4. Quick Check:

    Count braces to find missing one [OK]
Hint: Count opening and closing braces carefully [OK]
Common Mistakes:
  • Thinking string age is invalid
  • Ignoring missing braces
  • Assuming keys don't need quotes
5. You want to store a list of tasks in Firebase using JSON tree structure. Which structure best supports adding tasks with unique IDs and their status?
hard
A. {"tasks": {"t1": {"done": false}, "t2": {"done": true}}}
B. {"tasks": [{"id": "t1", "done": false}, {"id": "t2", "done": true}]}
C. {"tasks": ["t1", "t2", "done"]}
D. {"tasks": {"done": false, "done": true}}

Solution

  1. Step 1: Understand Firebase JSON best practice

    Firebase prefers objects with unique keys for easy updates and queries, not arrays.
  2. Step 2: Analyze each option

    Arrays of objects are less efficient for direct access by ID and Firebase queries. Objects using unique IDs as keys enable paths like tasks/t1/done. Simple lists of strings or objects with duplicate keys are invalid or ineffective.
  3. Final Answer:

    {"tasks": {"t1": {"done": false}, "t2": {"done": true}}} -> Option A
  4. Quick Check:

    Use objects with unique keys for Firebase data [OK]
Hint: Use objects with unique keys, not arrays, in Firebase [OK]
Common Mistakes:
  • Using arrays instead of objects for unique keys
  • Duplicating keys in JSON
  • Storing data as simple lists without structure
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard