Simple JSON Handler in Java: Explanation & Practice

Read and parse simple JSON from file

Problem summary

Read a simple JSON file and extract specific values.

Starter code

import java.io.*;

public class Main {
    public static void main(String[] args) {
        // Read simple JSON: {"name": "John", "age": 30}
        // Extract and print values
        // Print: Name: <name>, Age: <age>
    }
}

Expected output and test cases

  • Extract values
    Name: John, Age: 30
  • Different values
    Name: Alice, Age: 25
  • Parse error
    Invalid JSON

Hints

  1. Simple regex or string parsing
  2. Find key, extract value after :
  3. Remove quotes from strings

Related File I/O exercises

Practice all File I/O exercises · Run this idea in the Java compiler