Skip to content

feat: More compact JSON formatting in the FileViewer#326

Merged
allison-truhlar merged 1 commit intoJaneliaSciComp:mainfrom
stuarteberg:fractured-json
Mar 13, 2026
Merged

feat: More compact JSON formatting in the FileViewer#326
allison-truhlar merged 1 commit intoJaneliaSciComp:mainfrom
stuarteberg:fractured-json

Conversation

@stuarteberg
Copy link
Contributor

@stuarteberg stuarteberg commented Mar 12, 2026

This is a small thing, but on a whim I asked my friend Claude O to give it a try. (Sadly, it didn't 1-shot the implementation, but it was close.)

I don't like reading unformatted JSON, but I also don't love the maximally-expanded JSON that most "pretty printing" functions produce.

The FracturedJsonJs library produces something I like better. It includes some options to control exactly how it formats JSON, but in this PR, I'm mostly using the defaults.

Example:

plain indented formatting (old)
{
  "janelia": {
    "projections": {
      "0": {
        "xy": "projections/zMAX-NP08_R2_2_1_SS83741_Gpb5_546_ITP_647_1x_LOL.png"
      }
    }
  },
  "multiscales": [
    {
      "axes": [
        {
          "name": "t",
          "type": "time"
        },
        {
          "name": "c",
          "type": "channel"
        },
        {
          "name": "z",
          "type": "space",
          "unit": "micrometer"
        },
        {
          "name": "y",
          "type": "space",
          "unit": "micrometer"
        },
        {
          "name": "x",
          "type": "space",
          "unit": "micrometer"
        }
      ],
      "datasets": [
        {
          "coordinateTransformations": [
            {
              "scale": [
                1,
                1,
                0.42589198869287453,
                0.23296123369249422,
                0.23296123369249422
              ],
              "type": "scale"
            }
          ],
          "path": "0"
        },
        {
          "coordinateTransformations": [
            {
              "scale": [
                1,
                1,
                0.42589198869287453,
                0.46592246738498844,
                0.46592246738498844
              ],
              "type": "scale"
            }
          ],
          "path": "1"
        },
        {
          "coordinateTransformations": [
            {
              "scale": [
                1,
                1,
                0.42589198869287453,
                0.9318449347699769,
                0.9318449347699769
              ],
              "type": "scale"
            }
          ],
          "path": "2"
        },
        {
          "coordinateTransformations": [
            {
              "scale": [
                1,
                1,
                0.42589198869287453,
                1.8636898695399537,
                1.8636898695399537
              ],
              "type": "scale"
            }
          ],
          "path": "3"
        }
      ],
      "metadata": {
        "method": "loci.common.image.SimpleImageScaler",
        "version": "Bio-Formats 7.2.0"
      },
      "name": "",
      "version": "0.4"
    }
  ],
  "omero": {
    "channels": [
      {
        "active": true,
        "coefficient": 1,
        "color": "00FF00",
        "family": "linear",
        "inverted": false,
        "label": "Cam1-T1",
        "window": {
          "end": 12282,
          "max": 12282,
          "min": 40,
          "start": 40
        }
      },
      {
        "active": true,
        "coefficient": 1,
        "color": "FF00FF",
        "family": "linear",
        "inverted": false,
        "label": "Cam2-T1",
        "window": {
          "end": 65535,
          "max": 65535,
          "min": 72,
          "start": 72
        }
      },
      {
        "active": true,
        "coefficient": 1,
        "color": "FF0000",
        "family": "linear",
        "inverted": false,
        "label": "Cam2-T2",
        "window": {
          "end": 8176,
          "max": 8176,
          "min": 60,
          "start": 60
        }
      },
      {
        "active": false,
        "coefficient": 1,
        "color": "00FFFF",
        "family": "linear",
        "inverted": false,
        "label": "Cam1-T3",
        "window": {
          "end": 18116,
          "max": 18116,
          "min": 82,
          "start": 82
        }
      }
    ],
    "rdefs": {
      "defaultT": 0,
      "defaultZ": 333,
      "model": "color"
    }
  }
}
formatted with FracturedJson (new)
{
  "janelia"    : {
    "projections": { "0": {"xy": "projections/zMAX-NP08_R2_2_1_SS83741_Gpb5_546_ITP_647_1x_LOL.png"} }
  },
  "multiscales": [
    {
      "axes"    : [
        {"name": "t", "type": "time"                         },
        {"name": "c", "type": "channel"                      },
        {"name": "z", "type": "space",   "unit": "micrometer"},
        {"name": "y", "type": "space",   "unit": "micrometer"},
        {"name": "x", "type": "space",   "unit": "micrometer"}
      ],
      "datasets": [
        {
          "coordinateTransformations": [
            { "scale": [1, 1, 0.42589198869287453, 0.23296123369249422, 0.23296123369249422], "type": "scale" }
          ],
          "path": "0"
        },
        {
          "coordinateTransformations": [
            { "scale": [1, 1, 0.42589198869287453, 0.46592246738498844, 0.46592246738498844], "type": "scale" }
          ],
          "path": "1"
        },
        {
          "coordinateTransformations": [
            { "scale": [1, 1, 0.42589198869287453, 0.9318449347699769, 0.9318449347699769], "type": "scale" }
          ],
          "path": "2"
        },
        {
          "coordinateTransformations": [
            { "scale": [1, 1, 0.42589198869287453, 1.8636898695399537, 1.8636898695399537], "type": "scale" }
          ],
          "path": "3"
        }
      ],
      "metadata": {"method": "loci.common.image.SimpleImageScaler", "version": "Bio-Formats 7.2.0"},
      "name"    : "",
      "version" : "0.4"
    }
  ],
  "omero"      : {
    "channels": [
      {
        "active"     : true,
        "coefficient": 1,
        "color"      : "00FF00",
        "family"     : "linear",
        "inverted"   : false,
        "label"      : "Cam1-T1",
        "window"     : {"end": 12282, "max": 12282, "min": 40, "start": 40}
      },
      {
        "active"     : true,
        "coefficient": 1,
        "color"      : "FF00FF",
        "family"     : "linear",
        "inverted"   : false,
        "label"      : "Cam2-T1",
        "window"     : {"end": 65535, "max": 65535, "min": 72, "start": 72}
      },
      {
        "active"     : true,
        "coefficient": 1,
        "color"      : "FF0000",
        "family"     : "linear",
        "inverted"   : false,
        "label"      : "Cam2-T2",
        "window"     : {"end": 8176, "max": 8176, "min": 60, "start": 60}
      },
      {
        "active"     : false,
        "coefficient": 1,
        "color"      : "00FFFF",
        "family"     : "linear",
        "inverted"   : false,
        "label"      : "Cam1-T3",
        "window"     : {"end": 18116, "max": 18116, "min": 82, "start": 82}
      }
    ],
    "rdefs"   : {"defaultT": 0, "defaultZ": 333, "model": "color"}
  }
}

Replace JSON.stringify with FracturedJson formatter for more compact,
readable output — short arrays and small objects stay on one line.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@allison-truhlar allison-truhlar self-requested a review March 13, 2026 10:59
Copy link
Collaborator

@allison-truhlar allison-truhlar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks Stuart! This was an outstanding issue from this previous PR: #280 (comment)

@allison-truhlar allison-truhlar merged commit f441c76 into JaneliaSciComp:main Mar 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants