Split file loading into two separate buttons

- Add 'Load an Object' button for standard JSON files (.json)
- Add 'Load a Log File' button for JSON Lines files (.log)
- Each button has specific file type filter and handling logic
- Improved user experience with clear separation of functionality
- Add styling for the new info button (log files)
- Update documentation to reflect the two-button approach
This commit is contained in:
2026-01-18 13:57:44 +01:00
parent d9114bf48e
commit 48d540bd48
4 changed files with 62 additions and 32 deletions

View File

@@ -9,9 +9,11 @@ The tool in this repository is designed to help users validate and test JMESPath
The application is single page. The page is divided into three sections:
- Top section: Title and description of the tool.
- Middle section: Input area for JMESPath expressions
- Bottom left section: Input area for JSON data
- Bottom right section: Output are for JMESPath query results
- Middle section:
- Input area for JMESPath expressions
- Lower Middle left section: Input area for JSON data
- Lower Middle right section: Output are for JMESPath query results
- Boottom section: Footer with author and license information
The Middle section also contains a toolbar with buttons to load data from disk, load sample data, format JSON input, and clear all inputs.

View File

@@ -75,14 +75,14 @@ npm run docker:run
1. **Enter a JMESPath expression** in the top input field (e.g., `people[*].name`)
2. **Add JSON data** using one of these methods:
- **Load from disk**: Click "📁 Load from Disk" to upload files
- `.json` files: Standard JSON format
- `.log` files: JSON Lines format (each line is a JSON object, automatically converted to array)
- **Load an Object**: Click "📄 Load an Object" to upload standard JSON files (.json)
- **Load a Log File**: Click "📋 Load a Log File" to upload JSON Lines files (.log) - each line converted to array
- **Paste or type**: Enter JSON data directly in the bottom-left textarea
- **Load sample**: Use the "Load Sample" button for quick testing
3. **View the results** in the bottom-right output area
4. **Use the toolbar buttons** to:
- Load JSON data from local files
- Load JSON objects from standard .json files
- Load log files from JSON Lines .log files (auto-converted to arrays)
- Load sample data for testing
- Format JSON for better readability
- Clear all inputs

View File

@@ -119,7 +119,7 @@ function App() {
const loadFromDisk = () => {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = '.json,.log';
fileInput.accept = '.json';
fileInput.onchange = (event) => {
const file = event.target.files[0];
if (file) {
@@ -127,35 +127,50 @@ function App() {
reader.onload = (e) => {
try {
const content = e.target.result;
let jsonContent;
// Handle .json files as regular JSON
JSON.parse(content); // Validate JSON
setJsonData(content);
setJsonError('');
} catch (err) {
setJsonError(`Invalid JSON file: ${err.message}`);
}
};
reader.readAsText(file);
}
};
fileInput.click();
};
// Handle .log files as sequences of JSON objects (JSON Lines format)
if (file.name.toLowerCase().endsWith('.log')) {
const lines = content.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0);
const loadLogFile = () => {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = '.log';
fileInput.onchange = (event) => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
try {
const content = e.target.result;
const lines = content.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0);
const jsonObjects = [];
for (const line of lines) {
try {
const obj = JSON.parse(line);
jsonObjects.push(obj);
} catch (lineError) {
throw new Error(`Invalid JSON on line: "${line.substring(0, 50)}..." - ${lineError.message}`);
}
const jsonObjects = [];
for (const line of lines) {
try {
const obj = JSON.parse(line);
jsonObjects.push(obj);
} catch (lineError) {
throw new Error(`Invalid JSON on line: "${line.substring(0, 50)}..." - ${lineError.message}`);
}
jsonContent = JSON.stringify(jsonObjects, null, 2);
} else {
// Handle .json files as regular JSON
JSON.parse(content); // Validate JSON
jsonContent = content;
}
const jsonContent = JSON.stringify(jsonObjects, null, 2);
setJsonData(jsonContent);
setJsonError('');
} catch (err) {
setJsonError(`Invalid file content: ${err.message}`);
setJsonError(`Invalid log file: ${err.message}`);
}
};
reader.readAsText(file);
@@ -195,9 +210,16 @@ function App() {
<button
className="btn btn-outline-success btn-sm me-2"
onClick={loadFromDisk}
title="Load JSON from disk"
title="Load JSON object from file"
>
📁 Load from Disk
📄 Load an Object
</button>
<button
className="btn btn-outline-info btn-sm me-2"
onClick={loadLogFile}
title="Load JSON Lines log file"
>
📋 Load a Log File
</button>
<button
className="btn btn-outline-primary btn-sm me-2"

View File

@@ -65,6 +65,12 @@ code {
color: white;
}
.btn-outline-info:hover {
background-color: #17a2b8;
border-color: #17a2b8;
color: white;
}
.header-section {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;