Stream: implementers
Topic: Retrieve descriptive error for json parsing
Leonardo Webb (Jan 08 2019 at 20:00):
Hi there,
I am trying to parse a JSON object using the .net core FHIR library. I am able to parse correctly made FHIR objects, but I have one file that is unable to be parsed. This is fine, however it is quite large and I am not sure where the problem actually is. Whenever I try to parse it, the FhirJsonParser
object that I am using only throws out this message: Input string was not in a correct format.
, and the stack trace is not particularly informative either (only complaining about being unable to parse a number, however, no location in the JSON specifies this). How can I get the line number/location that is an issue?
Thanks
Lloyd McKenzie (Jan 08 2019 at 21:40):
@Brian Postlethwaite @Ewout Kramer ?
Leonardo Webb (Jan 08 2019 at 21:51):
Just to add on since I have done some searching...
Effectively I am trying to capture the same output that the HAPI-FHIR CLI tool does, which is that it returns a list of validation errors, running this ./hapi-fhir-cli validate -v dstu3 -n fhir.json
, for example, gives me a list of all of the invalid attributes in the JSON. I found an older GitHub issue that seems to be similar to what I am trying to do, but I'm not sure if it is still relevant: https://github.com/ewoutkramer/fhir-net-api/issues/151 (that is, do I still need to convert my JSON to XML and then validate against that?). Reading through the code I don't see analogues to the Java classes (ex, SingleValidationMessage
), although I may be poking in the wrong places...
Ewout Kramer (Jan 23 2019 at 17:44):
Hi there,
I am trying to parse a JSON object using the .net core FHIR library. I am able to parse correctly made FHIR objects, but I have one file that is unable to be parsed.
Hi Leonardo, the Format exception should contain a location, and the parsing errors are actually pretty extensive and precise, so I have no idea what's going on. Could you send me the file containing the error?
As for the validation you are showing in hapi, this is done by the validator, not the parser. The validator is part of the API, you can find an example of how to use it here: https://github.com/ewoutkramer/Furore.Fhir.ValidationDemo
Last updated: Apr 12 2022 at 19:14 UTC