I have begun my journey into gamma (again) by trying to read values from a json file. I am getting a bit of success, but it is not quite like I want it.
My problem is that i need the value in the field “Vaerdi” when I have a certain “AnalysetypeId” see attached zip for patch and a sample json file. I do get that, but besides the correct slices, I also get empty slices.
I also feel that I am not doing this in an optimal way.
So any advice on how I can just get the slices that have the right content?
You could use XPathGetValues with this query : /Svaroversigt/Svaroversigt/Laboratorieresultater[AnalysetypeId="iupac_NPU03568"]/Vaerdi. You would retrieve all the Vaerdi where AnalysetypeId is iupac_NPU03568.
Pro tip : there is a Visual Studio Code plugin called XML Tools that allows you to highlight some portion of an XML document and automagically give you the correct XPath query to retrieve it.
just to add to @sebescudie’s Pro Tip, you can do the same in chrome or Firefox by using the dev tools (Ctrl+Shift+I in FF), then navigating to the specific element and selecting, then: right click/Copy/XPath:
Hey @sunep, I do remember cooking up some regex or similar for you in the past, glad to hear you are porting it to gamma : ) .
Have you looked at the “Read JSON” help patch? It shows how you get an XDocument from a JSON file, you can then use XPath to navigate and get what you need as if it was XML:
One more thing TryParse fails (at least on my system) when a comma is used as decimal separator.
So when you want to convert the strings to float you maybe have too replace it with a dot beforehand.
@bjoern Thanks a lot. I have now also fitered out elements that are failed responses. thanks a lot. Now I have something that is almost elegant and very usable.