clang-format a json file

Viewed 2517

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?

4 Answers

I've been working on getting this accepted, https://reviews.llvm.org/D93528, this does what you suggest by adding a hidden "x = " at the front of the file, then remove that after formatting using the replacement mechanism.

Until this gets landed I think you could do something similar perhaps with clang-apply-replacements

Related