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
- Simple regex or string parsing
- Find key, extract value after :
- Remove quotes from strings
Related File I/O exercises
- Practice Config File Parser in Java
- Practice File Difference Checker in Java
- Practice CSV Parser in Java
Practice all File I/O exercises · Run this idea in the Java compiler