-
Notifications
You must be signed in to change notification settings - Fork 1
Home
This project provides a simple utility to generate SQL (or other format) queries from a JSON resource file containing region data.
- The application entry point is the
Main
(src/main/java/Main.java) class. - It loads a JSON file
region.json
(src/main/java/resources/region.json) and invokes theGenerator
class to process it. - The JSON file must follow a specific structure (see Input Format).
- The program outputs generated queries to a file (see Output Format).
- Clone or download the repository.
- Make sure you have Maven installed.
- Open the project in your preferred IDE (IntelliJ, Eclipse, VS Code, etc.).
- Run the
Main
class.
mvn clean compile exec:java -Dexec.mainClass="Main"
The input JSON file must be located at src/main/java/resources/region.json
Example Input:
{ "geometries": [ { "type": "Polygon", "properties": { "name": "Los Angeles", "zip": "90001", "state": "CA" }, "arcs": "78179, 78180, 78181, 78182, 78183, 78184" }, { "type": "Polygon", "properties": { "name": "San Diego", "zip": "92101", "state": "CA" }, "arcs": "79255, 79256, 79257, 79258, 79259, 79260, 79261" } ] }
When executed, the program generates the SQL file in a platform-specific directory:
- macOS/Linux: /Users//jsonToQuery/insert-geometry.sql
- Windows: C:\Users<your-username>\jsonToQuery\insert-geometry.sql
Example Output:
INSERT INTO map.geometry (geometryType, regionName, zipCode, stateCode, arcs, idstatefk) VALUES
('Polygon','LOS ANGELES',90001,'CA','78179, 78180, 78181, 78182, 78183, 78184',5),
('Polygon','SAN DIEGO',92101,'CA','79255, 79256, 79257, 79258, 79259, 79260, 79261',5);
- Java 11+
- Maven 3.6+
- Jackson library (for JSON parsing)
- Reads input JSON and maps it to Java objects.
- Automatically creates cross-platform directory and file.
- Generates SQL insert statements with correct formatting.
- Writes output to insert-geometry.sql.
- Logs progress and error messages to the console.
- The project uses Jackson’s ObjectMapper for JSON deserialization.
- The StateMap class provides a mapping between US state codes and their internal IDs.
- If the JSON structure is invalid, an error will be printed.
- Existing output files will be overwritten each run.