I’m interested in using HJSON but it’s quite annoying to run hjson every time and create a json file that I can then read with JSON3. How would I go about creating a HJSON.jl such that I can do the conversion inside julia which would already be an improvement and then probably just have a readhjson function that goes through conversion and reading it using JSON3 in one go.
Looking forward to any pointers of how to create such a wrapper package.
I don’t see why that’s a problem. The tool doesn’t require installation, it’s just an ELF binary that can be downloaded and extracted from the homepage.
curl -L https://github.com/hjson/hjson-go/releases/download/v4.4.0/hjson_v4.4.0_linux_amd64.tar.gz | tar xz ./hjson
In this case, you need to modify the above julia snippet to call ./hjson instead of plain hjson, otherwise it won’t be able to find the binary, but that’s it. You can carry a copy of the hjson binary with your code, even commit it into your repository, etc.
If you really need, you can even make this part of your julia code:
using JSON
const URL = "https://github.com/hjson/hjson-go/releases/download/v4.4.0/hjson_v4.4.0_linux_amd64.tar.gz"
function hjson_parse(file::AbstractString; kwargs...)
if !isfile("hjson")
run(pipeline(`curl -sL $URL`, `tar xz ./hjson`))
end
json = Pipe()
run(pipeline(`./hjson -c $file`, json); wait = false)
return JSON.parse(json; kwargs...)
end