I have a json file. If I run clang-format on it, it formats it as though it's code (ugly).
{
"name" : "My great app",
"description" : "It's really cool.",
"version" : "0.0.1"
}
If I put 'foo = ' at the start of the file, it's great, but it's not json anymore.
foo = {
"name" : "My great app",
"description" : "It's really cool.",
"version" : "0.0.1"
}
How can I get clang-format to format the bare object in the json file as in the second example?
You can format your JSON document using Ctrl+Shift+I or Format Document from the context menu.
You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.
Short answer: YES. The clang-format tool has a -sort-includes option. Changing the order of #include directives can definitely change the behavior of existing code, and may break existing code.
Another program that I like to use is jq. It's pretty easy to use, and the documentation is great. For example, for simple reformatting you can do this:
jq . test.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With