Stan's JSON data type has a few custom features, particularly when it comes to complex numbers and tuple types, that json.dumps
does not handle correctly.
The JSON processing we use in cmdstanpy is available in the stanio package which is small and standalone. If it was added as a dependency in the [stan]
group, then stanio.dump_stan_json
would be a great replacement to json.dumps
to handle these types (and match e.g. cmdstanpy's behavior in other cases like pandas sequences)