Resolving JSON File Conflicts

Fix merge conflicts in JSON configuration files (tsconfig, eslintrc, settings). Handle trailing commas, nested objects, and array merges.

Common Patterns

Detailed Explanation

JSON File Conflicts

JSON files are a frequent source of merge conflicts because they are used for configuration (tsconfig.json, .eslintrc.json), package management (package.json), and data storage. JSON's strict syntax — no trailing commas, no comments — makes conflicts especially problematic because even a small mistake produces invalid JSON.

Common JSON Conflict Types

Top-level property additions: Both branches add new keys to the same JSON object.

{
<<<<<<< HEAD
  "compilerOptions": { "strict": true },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
=======
  "compilerOptions": { "strict": true, "esModuleInterop": true },
  "include": ["src/**/*", "tests/**/*"]
>>>>>>> feature/test-setup
}

Array element conflicts: Both branches add items to the same array.

Nested object conflicts: Both branches modify different properties inside a deeply nested object, but Git sees the whole block as conflicting.

Resolution Best Practices

  1. Parse both sides mentally: Understand the complete JSON structure each branch intended.
  2. Use Manual Edit: JSON conflicts almost always need manual resolution to ensure valid syntax.
  3. Watch for commas: The most common post-resolution error is a missing or extra comma.
  4. Validate the result: Paste the resolved JSON into a JSON formatter to verify syntax before saving.

Formatting Consistency

After resolving, run your project's formatter (Prettier, etc.) to normalize indentation and trailing commas. This ensures the next person to edit the file does not create unnecessary diff noise.

Use Case

Two branches modified tsconfig.json — one added strict TypeScript options while the other configured test file paths. Git cannot merge the overlapping JSON structure changes.

Try It — Git Conflict Resolver

Open full tool