Skip to content

Add Swift section with JSONCKit link#16

Open
steelbrain wants to merge 1 commit intoJSONC-org:mainfrom
steelbrain:patch-1
Open

Add Swift section with JSONCKit link#16
steelbrain wants to merge 1 commit intoJSONC-org:mainfrom
steelbrain:patch-1

Conversation

@steelbrain
Copy link

@steelbrain steelbrain commented Mar 15, 2026

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
~/P/t/jsonc-parser ❯❯❯ tree
.
├── Package.resolved
├── Package.swift
└── Sources
    └── jsonc-parser
        └── main.swift

3 directories, 3 files
~/P/t/jsonc-parser ❯❯❯ cat Sources/jsonc-parser/main.swift
import Foundation
import JSONCKit

let inputData = FileHandle.standardInput.readDataToEndOfFile()

guard !inputData.isEmpty else {
    exit(0)
}

do {
    let jsonData = try JSONC.convertToData(inputData)
    FileHandle.standardOutput.write(jsonData)
} catch {
    FileHandle.standardError.write("Error: \(error.localizedDescription)\n".data(using: .utf8)!)
    exit(1)
}
~/P/t/jsonc-parser ❯❯❯ cat Package.swift
// swift-tools-version: 6.0

import PackageDescription

let package = Package(
    name: "jsonc-parser",
    platforms: [.macOS(.v10_15)],
    dependencies: [
        .package(url: "https://github.com/steelbrain/JSONCKit.git", from: "1.0.0"),
    ],
    targets: [
        .executableTarget(
            name: "jsonc-parser",
            dependencies: [.product(name: "JSONCKit", package: "JSONCKit")]
        ),
    ]
)
~/P/t/jsonc-parser ❯❯❯ echo '{ /* comment */ "key": "value" }' | swift run jsonc-parser
[1/1] Planning build
Building for debugging...
[1/1] Write swift-version--58304C5D6DBC2206.txt
Build of product 'jsonc-parser' complete! (0.10s)
{               "key": "value" }

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant