Skip to content

Commit 37d4045

Browse files
committed
[ADDED] Sample JSON5 files for test app
1 parent 49e59fe commit 37d4045

File tree

6 files changed

+106
-4
lines changed

6 files changed

+106
-4
lines changed

app/src/main/kotlin/App.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,31 @@ import io.github.json5.kotlin.JSON5
55
fun main() {
66
val json5files = listOf(
77
"empty-json.json5",
8+
"simple-object.json5",
9+
"array-example.json5",
10+
"numeric-formats.json5",
11+
"string-and-identifiers.json5",
12+
"root-string.json5"
813
)
914

1015
json5files.forEach { fileName ->
11-
println("Processing file: $fileName")
16+
println("\n=== Processing file: $fileName ===")
1217
// Load the file from resources using the classloader
1318
val resourceStream = object {}.javaClass.getResourceAsStream("/$fileName")
1419

1520
if (resourceStream != null) {
1621
val content = resourceStream.bufferedReader().use { it.readText() }
17-
JSON5.parse(content).also { parsed ->
18-
println("Parsed JSON5: $parsed")
22+
println("Content:\n$content")
23+
try {
24+
JSON5.parse(content).also { parsed ->
25+
println("\nParsed JSON5: $parsed")
26+
}
27+
} catch (e: Exception) {
28+
println("\n⚠️ Error parsing JSON5: ${e.message}")
1929
}
2030
} else {
21-
println("Error: Could not find resource: $fileName")
31+
println("⚠️ Error: Could not find resource: $fileName")
2232
}
33+
println("\n===============================\n\n")
2334
}
2435
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
// This is an array with different data types
3+
42,
4+
"Hello World",
5+
true,
6+
null,
7+
{
8+
name: 'Nested object',
9+
active: true,
10+
},
11+
[1, 2, 3], // Nested array
12+
Infinity, // Special numeric values
13+
-Infinity,
14+
NaN,
15+
// Trailing comma is valid in JSON5
16+
]
17+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
/* Multi-line comment example
3+
showing various numeric formats
4+
supported by JSON5 */
5+
6+
// Regular numbers
7+
integer: 42,
8+
negative: -17,
9+
float: 3.14159,
10+
11+
// Numbers with different formats
12+
leadingDecimal: .25, // Leading decimal point
13+
trailingDecimal: 5., // Trailing decimal point
14+
positiveSign: +42, // Explicit positive sign
15+
16+
// Hexadecimal numbers
17+
hex: 0xC0FFEE, // Uppercase hex
18+
smallHex: 0xff, // Lowercase hex
19+
negativeHex: -0x7B, // Negative hex
20+
21+
// Scientific notation
22+
scientific: 6.02e23, // Regular scientific notation
23+
negativeExp: 1e-10, // Negative exponent
24+
positiveExp: 1.5e+4, // Explicit positive exponent
25+
26+
// Special numeric values
27+
infinite: Infinity,
28+
negativeInfinite: -Infinity,
29+
notANumber: NaN,
30+
}
31+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Root-level values can be strings, numbers, booleans, or null in JSON5
2+
"This is a valid root-level string in JSON5"
3+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
// This is a simple object with various types of values
3+
name: "John Doe", // Unquoted property name
4+
age: 30,
5+
isEmployed: true,
6+
salary: 75000.50,
7+
address: {
8+
street: '123 Main St', // Single-quoted string
9+
city: "New York",
10+
zipCode: 10001
11+
}
12+
}
13+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
// String escape sequences
3+
escapes: 'Escaped characters: \b \f \n \r \t \v \0 \x0F \u00A9',
4+
quotes: "He said, \"Hello!\"",
5+
singleQuotes: 'It\'s working',
6+
multiline: 'This string \
7+
spans multiple \
8+
lines',
9+
lineSeparators: 'Line\u2028and\u2029paragraph separators',
10+
11+
// Special identifiers as keys
12+
$special_key: "Dollar sign prefix",
13+
_under_score: "Underscore prefix",
14+
ùñîçødë: "Unicode property name",
15+
16+
// Escaped property names
17+
\u0061\u0062\u0063: "abc via Unicode escapes",
18+
19+
// Empty object and arrays
20+
emptyObject: {},
21+
emptyArray: [],
22+
23+
// Indentation and whitespace
24+
indentedProperty: 42,
25+
26+
// Root value example shown in another file
27+
}

0 commit comments

Comments
 (0)