What is easiest way to export annotation ROI for Python ML coding?

I can export .txt files with coordinates, but is there a way to get something similar to an xml? How to get a json file? All scripts I found allowed me to ‘print’ the coordinates on json but only on scripting text. how to get them into an actual file I can export?

Hi, see https://qupath.readthedocs.io/en/latest/docs/advanced/exporting_annotations.html

To write to a file, that’s all standard Groovy things - so I recommend searching for Groovy documentation on that.

Tricks like this work:

new File('/path/to/file.json').text = jsonString

When I try this script:

def annotations = getAnnotationObjects()
boolean prettyPrint = true
def gson = GsonTools.getInstance(prettyPrint)
println gson.toJson(annotations)
new File(’/path/to/file.json’).text = jsonString

I get the following:

ERROR: I cannot find ‘jsonString’!

Note that you’ll need to customize the script for your needs (e.g. actually input ‘/path/to/file.json’, not just copy & paste only).

def annotations = getAnnotationObjects()
boolean prettyPrint = true
def gson = GsonTools.getInstance(prettyPrint)
new File('/path/to/file.json').text = gson.toJson(annotations)
1 Like

Ok - thank you. i will try to work with it
Appreciate the support