# Markups ROI cannot be loaded from JSON file

**URL:** <https://discourse.slicer.org/t/markups-roi-cannot-be-loaded-from-json-file/25430>\
**Category:** Support\
**Tags:** python, markups\
**Created:** [September 26, 2022, 2:13am UTC](https://discourse.slicer.org/t/markups-roi-cannot-be-loaded-from-json-file/25430 "2022-09-26T02:13:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WilliamDaniel](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/williamdaniel/32/13425_2.png) [@WilliamDaniel](https://discourse.slicer.org/u/WilliamDaniel)\
**Post date:** [September 26, 2022, 2:13am UTC](https://discourse.slicer.org/t/markups-roi-cannot-be-loaded-from-json-file/25430/1 "2022-09-26T02:13:03Z")

</div>

System: WIN 10  
Slicer version: Slicer 5.0.3

Hi There,  
I’m trying to save markups ROI node as a markups JSON file programmatically.

First, I added a markups ROI node to the 3d view using ‘Markups’ module manually.  
And then, I saved the markups ROI node to a JSON file. I referenced the code snippet in the Script repository to do that: [Save markups to file](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#markups)

As shown in the figure below, here is the code I executed in the Python console:

```auto
markupsNode = slicer.util.getNode('R')
slicer.util.saveNode(markupsNode, slicer.app.defaultScenePath + "/" + "MyMarkups.mrk.json")

```

 ![ROI 1](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/9/79f1ede04ac8cf0520ef6268918c67f0bbbb1b64.png)

However, When I trying to load the markups from the JSON file, the ROI cannot be reloaded into 3D view, it is displayed as a dot instead of the box:

 ![ROI2](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/6/06fd2b85df778c92e594933ea21b7e2f9ef10530.png)

Here is the JSON file automatically created by the code snippet (MyMarkups.mrk.json):

```auto
{
    "@schema": "https://raw.githubusercontent.com/slicer/slicer/master/Modules/Loadable/Markups/Resources/Schema/markups-schema-v1.0.3.json#",
    "markups": [
        {
            "type": "ROI",
            "coordinateSystem": "LPS",
            "coordinateUnits": "mm",
            "locked": false,
            "fixedNumberOfControlPoints": false,
            "labelFormat": "%N-%d",
            "lastUsedControlPointNumber": 1,
            "controlPoints": [
                {
                    "id": "1",
                    "label": "R-1",
                    "description": "",
                    "associatedNodeID": "",
                    "position": [-46.1154670715332, -0.0, -11.705148696899414],
                    "orientation": [-1.0, -0.0, -0.0, -0.0, -1.0, -0.0, 0.0, 0.0, 1.0],
                    "selected": true,
                    "locked": false,
                    "visibility": true,
                    "positionStatus": "defined"
                }
            ],
            "measurements": [
                {
                    "name": "volume",
                    "enabled": false,
                    "units": "cm3",
                    "printFormat": "%-#4.4g%s"
                }
            ],
            "display": {
                "visibility": true,
                "opacity": 1.0,
                "color": [0.4, 1.0, 0.0],
                "selectedColor": [0.9372549019607843, 0.34901960784313726, 0.3843137254901961],
                "activeColor": [0.4, 1.0, 0.0],
                "propertiesLabelVisibility": true,
                "pointLabelsVisibility": false,
                "textScale": 3.0,
                "glyphType": "Sphere3D",
                "glyphScale": 1.0,
                "glyphSize": 5.0,
                "useGlyphScale": true,
                "sliceProjection": false,
                "sliceProjectionUseFiducialColor": true,
                "sliceProjectionOutlinedBehindSlicePlane": false,
                "sliceProjectionColor": [1.0, 1.0, 1.0],
                "sliceProjectionOpacity": 0.6,
                "lineThickness": 0.2,
                "lineColorFadingStart": 1.0,
                "lineColorFadingEnd": 10.0,
                "lineColorFadingSaturation": 1.0,
                "lineColorFadingHueOffset": 0.0,
                "handlesInteractive": true,
                "translationHandleVisibility": true,
                "rotationHandleVisibility": false,
                "scaleHandleVisibility": true,
                "interactionHandleScale": 3.0,
                "snapMode": "toVisibleSurface"
            }
        }
    ]
}

```

I found that the JSON file is missing the following keys under the “markups”:

```auto
"roiType":,
"center": ,
"orientation": ,
"size": ,
"insideOut",

```

Why is this happening? How do I need to modify the code snippet so that it can automatically generates a full JSON file containing the above keys to be able to reload the ROI box in the 3d view?

Thank you very much!

---

<div class="post-metadata">

**Author:** ![WilliamDaniel](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/williamdaniel/32/13425_2.png) [@WilliamDaniel](https://discourse.slicer.org/u/WilliamDaniel)\
**Post date:** [September 26, 2022, 2:44pm UTC](https://discourse.slicer.org/t/markups-roi-cannot-be-loaded-from-json-file/25430/2 "2022-09-26T14:44:37Z")

</div>

Another thing I’ve found is that after I execute the above code, even if I click the ‘SAVE’ button to regenerate a new JSON file, it’s still incomplete as shown above, which causes when I import the ‘mrml’ file to reload the scene, the ROI box can not be loaded.  
Is there any specific solutions?  
Thank you so much!

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [September 26, 2022, 2:48pm UTC](https://discourse.slicer.org/t/markups-roi-cannot-be-loaded-from-json-file/25430/3 "2022-09-26T14:48:12Z")

</div>

Thanks! I’m taking a look into it.

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [September 26, 2022, 3:02pm UTC](https://discourse.slicer.org/t/markups-roi-cannot-be-loaded-from-json-file/25430/4 "2022-09-26T15:02:16Z")

</div>

This issue should be fixed with this PR: [BUG: Ensure default JSON storage node is used in qSlicerMarkupsWriter by Sunderlandkyl · Pull Request #6551 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/pull/6551).

You can call “AddDefaultStorageNode()” as a workaround in Slicer 5.0.3:

```python
markupsNode = slicer.util.getNode('R')
markupsNode.AddDefaultStorageNode()
slicer.util.saveNode(markupsNode, slicer.app.defaultScenePath + "/" + "MyMarkups.mrk.json")

```

---

<div class="post-metadata">

**Author:** ![WilliamDaniel](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/williamdaniel/32/13425_2.png) [@WilliamDaniel](https://discourse.slicer.org/u/WilliamDaniel)\
**Post date:** [September 26, 2022, 3:20pm UTC](https://discourse.slicer.org/t/markups-roi-cannot-be-loaded-from-json-file/25430/5 "2022-09-26T15:20:16Z")

</div>

It worked, thanks a lot for your help!
