Add Swift section with JSONCKit link#16
Conversation
JSONCKit is heavily inspired by the https://github.com/marcozac/go-jsonc implementation, see [ATTRIBUTIONS](https://github.com/steelbrain/JSONCKit/blob/main/ATTRIBUTIONS.md). It borrows tests from a bunch of different libs in the ecosystem. I'm using it in some of my own macOS apps, happy to share it with the ecosystem.
|
Thanks for the PR. This could be a valuable ressource to add, however since it's not a parser nor a JSONC genertor, we should add it in a seperate category. Would you be ok with this being listed in a "JSONC to JSON Converter" category that would appear below the current list? |
|
Thanks for taking a look! It does support parsing/decoding but only in a typed manner to a shape directly: https://github.com/steelbrain/JSONCKit?tab=readme-ov-file#decode-a-decodable-type-directly I'm happy with it being placed where you feel is appropriate! I've ticked "allow edits by maintainers", please let me know how I should change it if I am to make this change! |
I see, in that case, we can keep it among the other parser libraries. One last thing before merging, can you confirm that |
|
Confirmed! Tested the following json blob with trailing commas and it worked well Source codeimport Foundation
import JSONCKit
let jsonc = """
{
// Server configuration
"host": "localhost",
"port": 8080,
"features": [
"auth",
"logging",
"metrics", // we may add more later
],
"database": {
"name": "mydb",
"pool_size": 5,
/* credentials loaded from env at runtime */
},
}
"""
struct Database: Decodable {
let name: String
let pool_size: Int
}
struct Config: Decodable {
let host: String
let port: Int
let features: [String]
let database: Database
}
let config = try JSONC.decode(Config.self, from: Data(jsonc.utf8))
assert(config.host == "localhost")
assert(config.port == 8080)
assert(config.features == ["auth", "logging", "metrics"])
assert(config.database.name == "mydb")
assert(config.database.pool_size == 5)
print("Parsed config:")
print(" host: \(config.host)")
print(" port: \(config.port)")
print(" features: \(config.features)")
print(" database: \(config.database.name) (pool: \(config.database.pool_size))") |
JSONCKit is heavily inspired by the https://github.com/marcozac/go-jsonc implementation, see ATTRIBUTIONS.
It borrows tests from a bunch of different libs in the ecosystem. I'm using it in some of my own macOS apps, happy to share it with the ecosystem.
Edit: Here's a very simple program that'd use it