Update: I just found this doc http://clang.llvm.org/docs/JSONCompilationDatabase.html that suggests an officially supported way to espace parameters (not entirely equivalent to this code though in the case of --option=value-with-spaces).