JSON Linter Test Application
Overview
This is a JSON linting test application built for NetBurner embedded systems. The application serves as a comprehensive test suite for validating JSON parsing capabilities, testing both valid JSON files (that should pass) and invalid JSON files (that should fail) to ensure the JSON parser correctly identifies various syntax errors and edge cases.
It will test all bad*.json and pass*.json files in html directory. To add additional tests add a bad or pass files to the html directory. pass*.json files are expected to pass and bad*.json are expected to fail.
- Note
- Some failures are considered warnings; they not legal JSON but we parse them for this test anyway.
Application Architecture
The application is built on the NetBurner RTOS platform and includes:
- Web Server Integration: Starts an HTTP server on port 80
- Network Stack: Full TCP/IP networking capabilities
- JSON Parser Testing: Comprehensive validation of JSON syntax
- File System Integration: Embedded file system containing test JSON files
Test Files
The application includes 47 JSON test files categorized into two groups:
Valid JSON Files (Should Pass)
- pass1.json: Comprehensive JSON test pattern with various data types, escape sequences, and formatting
- pass2.json: Deeply nested array structure (19 levels deep)
- pass3.json: Simple object validation test
- pass4.json: Complex configuration object with nested structures (network configuration example)
Invalid JSON Files (Should Fail)
Original Test Suite
- bad1.json: Invalid escape sequences (
\a
, \x
, incomplete \u
sequences)
- bad2.json: Unclosed arrays and objects, extra closing braces
- bad3.json: Missing opening brace
- bad4.json: Trailing commas in objects and arrays
- bad5.json: Invalid number formats (leading +, trailing decimals, hex notation, Infinity, NaN)
- bad6.json: Missing values after commas
- bad7.json: Missing commas between object properties
- bad8.json: Unquoted property names
- bad9.json: Complex nested errors (missing quotes, invalid numbers, trailing commas)
- bad10.json: Mismatched brackets and braces
- bad11.json: Comments in JSON (not allowed in strict JSON)
- bad12.json: Unescaped control characters in strings
Extended Test Suite
- bad_2.json: Unclosed array (missing closing bracket)
- bad_3.json: Unquoted object key (keys must be in quotes)
- bad_4.json: Trailing comma in array
- bad_5.json: Double trailing comma in array
- bad_6.json: Missing value at start of array (leading comma)
- bad_7.json: Comma after array close
- bad_8.json: Extra closing bracket
- bad_9.json: Trailing comma in object
- bad_10.json: Extra content after valid JSON (misplaced quoted value)
- bad_11.json: JavaScript expression instead of JSON value (1 + 2)
- bad_12.json: JavaScript function call instead of JSON value (alert())
- bad_13.json: Leading zeros in numbers (013)
- bad_14.json: Hexadecimal number notation (0x14)
- bad_15.json: Invalid backslash escape sequence (\x15)
- bad_16.json: Naked/unquoted value (not a string, number, boolean, or null)
- bad_17.json: Invalid octal escape sequence (\017)
- bad_19.json: Missing colon between key and value
- bad_20.json: Double colon (::)
- bad_21.json: Comma instead of colon in object
- bad_22.json: Colon instead of comma in array
- bad_23.json: Invalid boolean value ("truth" instead of "true")
- bad_24.json: Single quotes instead of double quotes for strings
- bad_25.json: Unescaped tab characters in string
- bad_26.json: Invalid escape sequences with tabs
- bad_27.json: Unescaped line break in string
- bad_28.json: Invalid line continuation with backslash
- bad_29.json: Incomplete scientific notation (0e)
- bad_30.json: Incomplete scientific notation with sign (0e+)
- bad_31.json: Invalid scientific notation with double sign (0e+-1)
- bad_32.json: Missing closing brace (comma instead of brace)
- bad_33.json: Mismatched brackets and braces (array opened, object closed)
- bad_34.json: Extra closing brace
Key Features Tested
String Handling
- Proper escape sequences (
\n
, \r
, \t
, \"
, \\
, \/
, \b
, \f
)
- Unicode escape sequences (
\u
followed by 4 hex digits)
- Invalid escape sequences detection
- Control character validation
- Quote character validation (double quotes required, single quotes invalid)
- Unescaped control characters (tabs, line breaks)
Number Validation
- Integer formats
- Floating-point numbers
- Scientific notation (e/E notation)
- Invalid number formats (leading zeros, trailing decimals, hex notation)
- Incomplete scientific notation (missing exponent values)
- Invalid scientific notation syntax (double signs, incomplete expressions)
Punctuation and Syntax Errors
- Missing or extra commas
- Missing or extra colons
- Misplaced punctuation (comma instead of colon, colon instead of comma)
- Trailing commas in objects and arrays
- Missing closing brackets or braces
- Extra closing brackets or braces
Invalid Values and Expressions
- JavaScript expressions (arithmetic operations, function calls)
- Naked/unquoted values that aren't valid JSON primitives
- Extra content after valid JSON structures
- Invalid boolean values (non-standard true/false representations)
- Single-quoted strings (JSON requires double quotes)
Edge Cases
- Deeply nested structures
- Empty objects and arrays
- Whitespace handling
- Comment detection (should fail in strict JSON)
Code Structure
Main Components
void TestJson(int i, bool should_pass)
Core testing function that:
- Creates a
ParsedJsonDataSet
object from file data
- Runs
CheckLint()
to validate JSON syntax
- Reports success/failure with detailed error messages
- Handles both expected passes and failures
void UserMain(void *pd)
Main function.
Definition PlatformSpecific/SAME70/MODM7AE70/ADC_Simple/src/main.cpp:42
Application entry point that:
- Initializes network stack and web server
- Iterates through all embedded files
- Tests files starting with 'b' (bad) as failures
- Tests files starting with 'p' (pass) as successes
Dependencies
- NetBurner RTOS: Real-time operating system
- HTML Files System: Embedded file system for test data
- JSON Lexer: Custom JSON parsing library
- Network Stack: TCP/IP networking support
Expected Output
The application produces console output for each test:
- Successful validation:
OK for filename.json
- Expected failure:
OK for filename.json [error_message]
- Unexpected pass:
Testing filename.json should fail, it passes.
- Unexpected failure:
Testing filename.json should pass, it fails. for error_message
Usage
- Deploy the application to a NetBurner embedded device
- The application automatically runs all JSON lint tests on startup
- Monitor console output for test results
- Access the embedded web server on port 80 for additional functionality
Development Notes
- The application uses embedded file records for test data
- All JSON files are compiled into the application binary
- The web server remains active after testing for additional functionality
- System diagnostics are enabled for debugging purposes
Test Coverage
This comprehensive test suite validates JSON parsing against a wide range of syntax errors and edge cases, ensuring robust JSON processing in embedded applications. The test suite covers:
- Basic JSON Structure: Objects, arrays, and proper nesting
- Data Types: Strings, numbers, booleans, null values
- String Formatting: Escape sequences, Unicode handling, control characters
- Number Formats: Integer, floating-point, scientific notation validation
- Syntax Rules: Comma placement, colon usage, bracket matching
- Error Conditions: All major categories of JSON syntax violations
- Edge Cases: Deeply nested structures, empty containers, whitespace handling
The test suite provides comprehensive coverage of JSON specification compliance and common parsing pitfalls, making it an excellent validation tool for JSON parser implementations.