Call for Beta Testers: New Flag `-fdiagnostics-as-json`

Hey everyone,

I wanted to share the addition of a new GHC flag to help users more easily parse diagnostic information. This is meant to ultimately replace the usage of -ddump-json. It was merged into master ~1 month ago.
If you have already added the nightlies channel to your ghcup, then you can find it in the release e.g. 9.9.20240208 by performing:

> ghcup install ghc 9.9.20240208
> ghcup set ghc 9.9.20240208

Here is an example possible output:
> ghc bad.hs -fdiagnostics-as-json

[1 of 1] Compiling Bad              ( ../tmp/bad.hs, ../tmp/bad.o )
{"version":"1.0","ghcVersion":"ghc-9.9.20230817","span":{"file":"bad.hs","start":{"line":9,"column":3},"end":{"line":9,"column":14}},"severity":"Error","code":88464,"message":["Variable not in scope: printLineas :: String -> IO a1"],"hints":[]}
{"version":"1.0","ghcVersion":"ghc-9.9.20230817","span":{"file":"bad.hs","start":{"line":10,"column":3},"end":{"line":10,"column":9}},"severity":"Error","code":88464,"message":["Variable not in scope: blaksh :: String -> IO ()"],"hints":[]}

The idea is to make it easier for external tools to parse error messages to make them easier to use. You can see the PR discussed here. You can see the JSON schema that the output data will conform to here (it is also hyperlinked to in the compiler flags section of the docs.

Please try it out on an array of errors via the -fdiagnostics-as-json flag and let us know what you think! Thanks a ton :slight_smile:


Awesome work Ben congratulations on getting this merged :smile:! Really excited to try this out for static-ls. Out of curiosity what’s the best place to provide any feedback if we have any?

1 Like