Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON: Lower indent level on formatted data #3007

Merged
merged 1 commit into from
Nov 17, 2019

Conversation

ferdnyc
Copy link
Contributor

@ferdnyc ferdnyc commented Sep 18, 2019

  • classes.json_data: Write output files with indent=1
  • windows/file_properties: Format "Output" listing with indent=2 (due to the proportional font)
    • (I also removed a separators arg from the file properties call, as it was set to the default values anyway.)

I'm all for pretty-printing, but JSON is a verbose enough format that all of the extra indentation just makes things unnecessarily wide, especially since our data is pretty heavily nested.

Before (excerpt:)

{
    "id": "27F47U42V0",
    "fps": {
        "num": 30,
        "den": 1
    },
    "display_ratio": {
        "num": 16,
        "den": 9
    },
    "pixel_ratio": {
        "num": 1,
        "den": 1
    },
    "width": 1280,
    "height": 720,
    "sample_rate": 48000,
    "channels": 2,
    "channel_layout": 3,
    "settings": {},
    "clips": [
        {
            "alpha": {
                "Points": [
                    {
                        "co": {
                            "X": 1.0,
                            "Y": 1.0
                        },
                        "interpolation": 2
                    }
                ]
            },
            "anchor": 0,
            "channel_filter": {
                "Points": [
                    {
                        "co": {
                            "X": 1.0,
                            "Y": -1.0
                        },
                        "interpolation": 2
                    }
                ]
            },

After (same excerpt):

{
 "id": "27F47U42V0",
 "fps": {
  "num": 30,
  "den": 1
 },
 "display_ratio": {
  "num": 16,
  "den": 9
 },
 "pixel_ratio": {
  "num": 1,
  "den": 1
 },
 "width": 1280,
 "height": 720,
 "sample_rate": 48000,
 "channels": 2,
 "channel_layout": 3,
 "settings": {},
 "clips": [
  {
   "alpha": {
    "Points": [
     {
      "co": {
       "X": 1.0,
       "Y": 1.0
      },
      "interpolation": 2
     }
    ]
   },
   "anchor": 0,
   "channel_filter": {
    "Points": [
     {
      "co": {
       "X": 1.0,
       "Y": -1.0
      },
      "interpolation": 2
     }
    ]
   },

- classes.json_data: Write output files with `indent=1`
- windows/file_properties: Format "Output" listing with `indent=2`
@jonoomph jonoomph merged commit 226c98a into OpenShot:develop Nov 17, 2019
@jonoomph
Copy link
Member

LG!

@ferdnyc ferdnyc deleted the json-indent branch November 19, 2019 03:10
@ferdnyc
Copy link
Contributor Author

ferdnyc commented Dec 10, 2019

I'm feeling even better about this change after having worked on the project file from #3123 .

The file there was damaged somehow (I hopefully repaired it), but because it came from OpenShot 2.4.4 release it used 4-space indents for the JSON nesting. Here's the difference between the original file's useful data (with the damaged part trimmed off), and that same file reindented to 1-space-per-level:

$ ls -l 100_TRIMMED.osp; ls -l 100_REINDENTED_TRIMMED.osp
-rw-r--r--. 1 ferd ferd 4.2M Dec 10 16:08 100_TRIMMED.osp
-rw-r--r--. 1 ferd ferd 2.2M Dec 10 16:09 100_REINDENTED_TRIMMED.osp

Fully 2MB / 4.2MB of the original file's data was made up of extraneous indentation!

@ferdnyc
Copy link
Contributor Author

ferdnyc commented Dec 10, 2019

(In the interest of fairness, it's also worth comparing those both to the original one-line file format, before pretty-printing.)

With all of the CRLF characters removed, all of the spaces compressed to a single space, and spaces removed immediately inside [] and {} blocks, the file size reduces further to 1.3MB:

$ ls -l 100_R_T_ONELINE.osp 
-rw-r--r--. 1 ferd ferd 1.3M Dec 10 16:24 100_R_T_ONELINE.osp

But I think the tradeoff from 1.3MB to 2.2MB is well worth it, for the extra readability/editability.

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