PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Salesforce

Flatten a nested JSON object

Last updated: May 22, 2026

Quick Overview

This question evaluates the ability to traverse and manipulate nested JSON-like structures, emphasizing concepts such as recursion or iterative traversal, array indexing, and path string construction; it tests data structures and serialization knowledge within the Coding & Algorithms domain and targets practical implementation skills for a software engineer role. It is commonly asked to assess how interviewees flatten hierarchical payloads for data processing or API normalization, reason about mixed object/array edge cases, and map hierarchical paths to primitive values.

  • medium
  • Salesforce
  • Coding & Algorithms
  • Software Engineer

Flatten a nested JSON object

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem You are given a JSON-like value representing an object that may contain: - **Objects / dictionaries** (string keys) - **Arrays / lists** - **Primitive values** (string/number/boolean/null) Return a **flattened map** from *path* to *primitive value*. ### Path rules - Use `.` to join object keys. - Use `[i]` for array indices. - The root has no leading separator. ### Examples **Input** ```json { "a": 1, "b": {"c": 2, "d": [3, 4]}, "e": [ {"f": 5}, 6 ] } ``` **Output** ```text a -> 1 b.c -> 2 b.d[0] -> 3 b.d[1] -> 4 e[0].f -> 5 e[1] -> 6 ``` ### Notes / constraints - Keys are strings and may contain any characters except `.` and `[` `]` (you may assume this to avoid escaping). - The output can be returned as a dictionary/map of `string -> primitive`. - Order does not matter. Implement a function to perform this flattening.

Quick Answer: This question evaluates the ability to traverse and manipulate nested JSON-like structures, emphasizing concepts such as recursion or iterative traversal, array indexing, and path string construction; it tests data structures and serialization knowledge within the Coding & Algorithms domain and targets practical implementation skills for a software engineer role. It is commonly asked to assess how interviewees flatten hierarchical payloads for data processing or API normalization, reason about mixed object/array edge cases, and map hierarchical paths to primitive values.

Related Interview Questions

  • Minimum Sum of Weekly Maximum Costs - Salesforce
  • Solve Two OA Coding Problems - Salesforce (medium)
  • Maximize events attended given date ranges - Salesforce (medium)
  • Implement common data-structure and JS tasks - Salesforce (medium)
  • Implement an LFU cache with O(1) operations - Salesforce (medium)
|Home/Coding & Algorithms/Salesforce

Flatten a nested JSON object

Salesforce logo
Salesforce
Jan 22, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
15
0
Practice Read
Loading...

Problem

You are given a JSON-like value representing an object that may contain:

  • Objects / dictionaries (string keys)
  • Arrays / lists
  • Primitive values (string/number/boolean/null)

Return a flattened map from path to primitive value.

Path rules

  • Use . to join object keys.
  • Use [i] for array indices.
  • The root has no leading separator.

Examples

Input

{
  "a": 1,
  "b": {"c": 2, "d": [3, 4]},
  "e": [ {"f": 5}, 6 ]
}

Output

a -> 1
b.c -> 2
b.d[0] -> 3
b.d[1] -> 4
e[0].f -> 5
e[1] -> 6

Notes / constraints

  • Keys are strings and may contain any characters except . and [ ] (you may assume this to avoid escaping).
  • The output can be returned as a dictionary/map of string -> primitive .
  • Order does not matter.

Implement a function to perform this flattening.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Salesforce•More Software Engineer•Salesforce Software Engineer•Salesforce Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.