Closed popsu closed 6 months ago
Thanks for this improvement! Should we maybe straight up switch to https://docs.rs/json5/latest/json5/?
Should we maybe straight up switch to https://docs.rs/json5/latest/json5/?
I'm not that familiar which JSONC crates one should use in Rust. I found the serde_jsonrc
by a little bit of googling, and it seems to work as a straight replacement.
I checked this json5
crate now that you mentioned it. Based on the docs it only implements from_str
and to_string
functions. So it can't be used as straight replacement, but some refactoring would be needed. Since it would be more work, there would have to be some upside to use this crate instead. With my limited knowledge about these I can't see any upside. I'm always open to learning, so let me know if there is some upside.
I'm probably missing something about how to use Serde with custom serializer/deserializer? :thinking:
Since the json5
implements serialize and deserialize, there should be a way to plug that somehow in to Serde, so we can use all these functions used in this vscli
without having to refactor any code? I just don't know how to.
Looking at the docs (second example) of json5
, seems that we could deserialize using json5
into serde_json::Value
and then use serde_json
functions after that.
Exactly.
You can just replace serde_jsonc
with serde
and add json5
.
You would then have to adjust parse_dev_container_config
to do it like this:
let content = std::fs::read_to_string(path)?;
let config: serde_json::Value = json5::from_str(&content)
Then we would get finally rid of serde_jsonc
which is kind of unofficial.
You could also add some simple unit tests to verify that tailing command and comments are not an issue.
I changed it to use a combination of serde_json
and json5
like you suggested, and I also added unit test to check that deserialization works for a devcontainer.json
file that has comments and trailing commas.
The current version doesn't like trailing commas in
devcontainer.json
file:This PR changes the
serde_jsonc
toserde_jsonrc
package allows the trailing commas.https://docs.rs/serde_jsonrc/latest/serde_jsonrc/