FastPrepFlatten JSON With Array Indices
Problems/Flatten JSON With Array Indices

Flatten JSON With Array Indices

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem flattens nested objects and arrays into pairs of a joined path and a value. The source is a post from June 2023 about interviews for a cloud team at Adobe. No feedback had arrived when it was written. This task came second in the first round, after a short tree exercise. The post asks how such data would be flattened and shows one sample. The sample input is written without quotes, and its output joins keys and array positions (counted from 0) with underscores. It gives no exact format, output order or limits.

Our choices: keys and plain values are runs of letters and digits, with no spaces. The top level is one object, and keys inside an object differ. Empty objects and arrays add no pairs. The answer is a list of [path, value] pairs in the order the values appear. Texts have 2 to 2000 characters, with brackets nested at most 100 deep. The examples are new.

Our version is about 80% the same as the reported question.

You get nested data written as text in a compact, JSON-like style without quotes:

  • An object is {, then zero or more key:value pairs separated by commas, then }.
  • An array is [, then zero or more values separated by commas, then ].
  • A value is an object, an array, or a plain value. Keys and plain values are runs of letters and digits.

The whole text is one object. Flatten it: for every plain value, output the pair [path, value]. The path joins, with _, every key and array position on the way from the outer object down to the value; array positions count from 0. For example, in {k:[x,{y:z}]} the value z has the path k_1_y.

Return the pairs in the order their values appear in text. Empty objects and empty arrays hold no values, so they add no pairs, but they still take up a position in an array.

Function

flattenJson(text: String) → List<List<String>>

Examples

Example 1

text = "{user:{name:ana,tags:[red,blue]},id:7}"return = [["user_name","ana"],["user_tags_0","red"],["user_tags_1","blue"],["id","7"]]

name sits inside user, so its path is user_name. The array tags holds red at index 0 and blue at index 1, giving user_tags_0 and user_tags_1. Then id holds 7. The pairs follow the order of the values in the text.

Example 2

text = "{grid:[[5,8],[3]]}"return = [["grid_0_0","5"],["grid_0_1","8"],["grid_1_0","3"]]

grid is an array of arrays. 5 and 8 are items 0 and 1 of item 0, and 3 is item 0 of item 1, so the paths are grid_0_0, grid_0_1 and grid_1_0.

Example 3

text = "{empty:{},list:[],v:0}"return = [["v","0"]]

An empty object and an empty array hold no values, so they add no pairs. Only v remains.

Constraints

  • 2 <= text.length <= 2000
  • text is one object in the format above, with no spaces.
  • Keys and plain values are runs of English letters and digits, and the keys inside one object are all different.
  • Brackets are nested at most 100 deep, counting the outer object.

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
  • Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
  • Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Decode StringSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
  • Plus and Minus CalculatorIndeed · PHONE SCREENIndeed interview questions
  • Arithmetic Expression EvaluatorMicrosoft · PHONE SCREENMicrosoft interview questions
  • Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
  • Evaluate an Arithmetic Expression with DivisionMotive · ONSITE INTERVIEWMotive interview questions
  • Parse a Partial JSON StreamListen Labs · PHONE SCREEN
  • Parse Nested Message TypesApplied Intuition · PHONE SCREENApplied Intuition interview questions

Interview reports that mention this question

  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
  • Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public List<List<String>> flattenJson(String text) {
        // Write your code here.
    }
}
Checking account…