postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.84k stars 839 forks source link

More concise JSON formatting #9882

Open tbrodbeck opened 3 years ago

tbrodbeck commented 3 years ago

Is your feature request related to a problem? Please describe. Current JSON Formatting looks like:

{
    "size": 1,
    "rows": [
        {
            "provider_type_id": "glossary",
            "tenant_id": "999",
            "metadata": {
                "modified_on": "2021-04-27T11:00:18.075Z",
                "classifications": [],
                "artifact_type": "glossary_term",
                "classification_global_ids": [],
                "name": "Geburtsdatum",
                "modified_by": "1000330999",
                "description": "Datum an dem eine Person geboren wurde",
                "state": "PUBLISHED",
                "steward_ids": [],
                "tags": [
                    "tag1",
                    "tag2"
                ]
            },
            "last_updated_at": 1619521218215,
            "categories": {
                "secondary_category_ids": [],
                "last_updated_at": 1619521218208,
                "secondary_category_global_ids": [],
                "primary_category_global_id": "5d2d5419-0032-4c64-90e2-ce68c6997bb5_285e46e3-70fc-4a11-b3d9-eb356df1fb42",
                "primary_category_id": "285e46e3-70fc-4a11-b3d9-eb356df1fb42",
                "primary_category_name": "Versicherte",
                "secondary_category_names": []
            },
            "artifact_id": "c4e7f896-0ae5-464a-a61e-78d929bb1313",
            "entity": {
                "artifacts": {
                    "synonym_global_ids": [],
                    "synonyms": [],
                    "global_id": "5d2d5419-0032-4c64-90e2-ce68c6997bb5_c4e7f896-0ae5-464a-a61e-78d929bb1313",
                    "effective_start_date": "2021-04-08T13:50:47.685Z",
                    "version_id": "0851f682-deca-44d9-9a32-db6c56961e75_10",
                    "abbreviation": [],
                    "artifact_id": "c4e7f896-0ae5-464a-a61e-78d929bb1313"
                }
            },
            "custom_attributes": [],
            "_score": 2.6100698
        }
    ],
    "aggregations": {}
}

Describe the solution you'd like A preferred more concise formatting (of pprint):

{"size": 1,
 "rows": [{"_score": 2.6100698,
           "artifact_id": "c4e7f896-0ae5-464a-a61e-78d929bb1313",
           "categories": {"last_updated_at": 1619521218208,
                          "primary_category_global_id": "5d2d5419-0032-4c64-90e2-ce68c6997bb5_285e46e3-70fc-4a11-b3d9-eb356df1fb42",
                          "primary_category_id": "285e46e3-70fc-4a11-b3d9-eb356df1fb42",
                          "primary_category_name": "Versicherte",
                          "secondary_category_global_ids": [],
                          "secondary_category_ids": [],
                          "secondary_category_names": []},
           "custom_attributes": [],
           "entity": {"artifacts": {"abbreviation": [],
                                    "artifact_id": "c4e7f896-0ae5-464a-a61e-78d929bb1313",
                                    "effective_start_date": "2021-04-08T13:50:47.685Z",
                                    "global_id": "5d2d5419-0032-4c64-90e2-ce68c6997bb5_c4e7f896-0ae5-464a-a61e-78d929bb1313",
                                    "synonym_global_ids": [],
                                    "synonyms": [],
                                    "version_id": "0851f682-deca-44d9-9a32-db6c56961e75_10"}},
           "last_updated_at": 1619521218215,
           "metadata": {"artifact_type": "glossary_term",
                        "classification_global_ids": [],
                        "classifications": [],
                        "description": "Datum an dem eine Person geboren wurde",
                        "modified_by": "1000330999",
                        "modified_on": "2021-04-27T11:00:18.075Z",
                        "name": "Geburtsdatum",
                        "state": "PUBLISHED",
                        "steward_ids": [],
                        "tags": ["tag1", "tag2"]},
           "provider_type_id": "glossary",
           "tenant_id": "999"}],
 "aggregations": {}}

-> 35% less lines. Clearer readability. Additional context Thats about it. Thank you.

DannyDainton commented 3 years ago

Hey @tbrodbeck

Thanks for the suggestion, I know this is a very subjective point and people will view this differently, I feel like your proposed solution is less readable than the current JSON formatting. As a human, it would take me a lot longer to scan through those nested objects.

I'm not sure that I believe that having a reduced amount of lines (35% in your suggestion) makes something instantly more readable - It could all be on a single line and be unreadable too people.

Just so I'm getting the full picture here, are you using a tool/plugin to add this formatting or has this been done manually in a text editor?

tbrodbeck commented 3 years ago

Hi Dainton. Thanks for your input.

I generated this formatting with Python:


import pprint
pprint.pprint({
    "size": 1,
    "rows": ["etc"],
    "aggregations": {}
})```