PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates parsing and string-processing skills, focusing on structural validation of JSON-like text including matching and nesting of brackets and correct handling of quoted strings with escape sequences.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Validate a JSON-like string

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem You are given a string `s` that is intended to be a JSON text. Implement a function `isValidJsonStructure(s) -> bool` that checks **structural validity** of the JSON with the following simplified rules: ### Rules to validate 1. After ignoring leading/trailing whitespace, the text must start and end with matching outer brackets: - either `{ ... }` or `[ ... ]`. 2. Brackets must be **properly nested and balanced**: - curly braces `{}` - square brackets `[]` 3. JSON strings are delimited by **double quotes** `"..."`. - While inside a string, any bracket characters (`{ } [ ]`) must be ignored for nesting purposes. - A quote preceded by an **odd** number of backslashes is escaped (e.g., `\"` closes? no; `\"` contains an escaped quote). In other words, `"` does **not** end a string. 4. You do **not** need to validate JSON key/value grammar (colons, commas, numbers, `true/false/null`, etc.). Only validate the above structural properties. ### Input/Output - **Input:** string `s` - **Output:** `true` if structurally valid per the rules; otherwise `false`. ### Constraints - `1 <= len(s) <= 1e5` ### Examples - `"{\"a\":[1,2,3]}"` → `true` - `"{[}]"` → `false` (bad nesting) - `"{\"x\":\"[}\"}"` → `true` (brackets inside a string are ignored) - `"{\"a\":\"unterminated}"` → `false` (unclosed string)

Quick Answer: This question evaluates parsing and string-processing skills, focusing on structural validation of JSON-like text including matching and nesting of brackets and correct handling of quoted strings with escape sequences.

Return whether a JSON-like string has matching outer brackets and balanced nested brackets while ignoring bracket characters inside strings.

Constraints

  • Only structural bracket validity is checked.
  • Quotes preceded by an odd number of backslashes are escaped.
  • JSON key/value grammar is not validated.

Examples

Input: ('{"a":[1,2,3]}',)

Expected Output: True

Explanation: Balanced brackets outside strings are valid.

Input: ('{[}]',)

Expected Output: False

Explanation: Bad nesting is invalid.

Input: ('{"x":"[not a bracket]"}',)

Expected Output: True

Explanation: Brackets inside strings are ignored.

Input: ('{"x":"a\\"b"}',)

Expected Output: True

Explanation: Escaped quotes do not end the string.

Input: ('abc',)

Expected Output: False

Explanation: The text must have matching outer brackets.

Hints

  1. Track strings separately from brackets.
  2. Use a stack for bracket nesting.
Last updated: Jun 27, 2026

Loading coding console...

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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)