vscode-sort-json icon indicating copy to clipboard operation
vscode-sort-json copied to clipboard

Sorting by data type. Grouping Primitive data type together and Complex data type together.

Open maxime4000 opened this issue 3 years ago • 2 comments

I'm looking at the documentation and I'm not sure how to interpret the docs about the settings configuration. I'm looking to sort JSON by Type, but I want it with those criteria :

  • Primitive data type first
    • Sorting without grouping primitive type. (string, number and others will be mixed together in the sorting)
  • Complex data type second

I guess I have 4 criteria of grouping. Something like this order :

  • primitive (string, number, boolean, null, undefined)
  • array of primitive ex: ["str1", "str2", 3, null, true, false]->No Object in this array
  • object
  • array of object or mixed data ex: [{...}, "2", {...}, 4, null, {...}, true, false]

The goal is to make :

  • Simple data first
  • Array of simple data second
  • Complex data third
  • Array of complex data fourth/last

To my understanding, the most similar feature is sorting by type, but it separate different primitive type which I prefer if it wouldn't happen.

I don't think the settings allow this type of customization, would appreciate some help if it can allow it. Otherwise, take this as a feature request :)

maxime4000 avatar Apr 21 '22 14:04 maxime4000

Here a JSON made to test the use case: I can provide with an expected sorting if ask. Otherwise I won't.

{
  "F": "string",
  "B": {
    "B": "string",
    "A": "string",
    "AObject": {
      "E": "string",
      "O": 3,
      "W": null,
      "H": 1,
      "B": false,
      "BObject": {
        "A": "string",
        "G": "string",
        "H": [
          {
            "C": "string",
            "A": "string"
          },
          {
            "C": "string",
            "A": {
              "A": "string"
            }
          }
        ],
        "B": {
          "A": "string"
        },
        "F": true,
        "D": {
          "A": "string",
          "D": "string",
          "C": "string"
        },
        "C": {
          "A": "string"
        },
        "E": "string"
      },
      "N": null,
      "ZObject": {
        "A": "string",
        "M": "string",
        "C": "string"
      },
      "M": "string",
      "L": 2,
      "D": "string",
      "R": false,
      "T": true,
      "C": "string"
    },
    "ZObject": {
      "A": "string",
      "G": "string",
      "D": "string",
      "C": "string"
    },
    "CObject": {
      "G": "string",
      "B": "string",
      "M": "string",
    }
  },
  "A": {
    "A": "string",
    "G": "string",
    "M": "string",
    "C": "string"
  },
  "C": {
    "A": "string",
    "G": "string",
    "M": "string",
    "C": "string"
  }
}

maxime4000 avatar Apr 21 '22 14:04 maxime4000

Thanks for the suggestion. I'm not able to have a look at this at the moment. Let me know if you are able to have a look at the code and I can give you some suggestions.

richie5um avatar Apr 22 '22 13:04 richie5um