{"id":18886205,"url":"https://github.com/lieutenantpeacock/lp-multisorter","last_synced_at":"2026-05-05T06:36:53.422Z","repository":{"id":57726333,"uuid":"392819596","full_name":"LieutenantPeacock/lp-multisorter","owner":"LieutenantPeacock","description":"Sorter for various file types. This is especially useful for comparing versions of generated files with differencing tools.","archived":false,"fork":false,"pushed_at":"2023-01-13T03:57:36.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-31T04:43:39.533Z","etag":null,"topics":["java","json","json-sorting","openapi-json","sort","xml","xmlsort"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LieutenantPeacock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-04T20:40:23.000Z","updated_at":"2022-08-14T22:02:41.000Z","dependencies_parsed_at":"2023-02-09T14:32:23.424Z","dependency_job_id":null,"html_url":"https://github.com/LieutenantPeacock/lp-multisorter","commit_stats":null,"previous_names":["lieutenantpeacock/multisorter"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LieutenantPeacock%2Flp-multisorter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LieutenantPeacock%2Flp-multisorter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LieutenantPeacock%2Flp-multisorter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LieutenantPeacock%2Flp-multisorter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LieutenantPeacock","download_url":"https://codeload.github.com/LieutenantPeacock/lp-multisorter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239859526,"owners_count":19708861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","json","json-sorting","openapi-json","sort","xml","xmlsort"],"created_at":"2024-11-08T07:25:44.825Z","updated_at":"2026-02-23T13:30:18.404Z","avatar_url":"https://github.com/LieutenantPeacock.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lt. Peacock's Multisorter\nDo you need to compare the differences between versions of generated XML, JSON, etc (e.g. WSDL files from Spring WS, OpenAPI JSON files generated by springdoc-openapi)? The generally unpredictable order often hinders this endeavor, showing a plethora of changes in differencing tools when only a few values have actually changed. Fortunately, Lt. Peacock's Multisorter has you covered.\n\nThis library/tool provides the ability to sort various file types.\n\n## Installation\nJDK 8 is required at a minimum.\n\nTo build the project as a single executable JAR:\n\n```\nmvn clean package -Pcli\n```\n\nFor those who do not want to build it manually, lp-multisorter-cli.jar can be downloaded from most of the [releases](https://github.com/LieutenantPeacock/lp-multisorter/releases) for direct use.\n\nTo see instructions on usage:\n\n```\njava -jar lp-multisorter.jar\n```\n\nThis project is also available as a [Maven artifact](https://search.maven.org/artifact/com.lt-peacock/lp-multisorter/1.3.0/jar). Maven users can include the library with the following dependency in pom.xml:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.lt-peacock\u003c/groupId\u003e\n  \u003cartifactId\u003elp-multisorter\u003c/artifactId\u003e\n  \u003cversion\u003e1.3.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## XML\nWith this tool, you can sort both elements and their attributes by name to facilitate comparing with differencing tools.\n\n### Command Line Usage\n```\njava -cp lp-multisorter.jar XMLSorter [inputFile] [outputFile]\n```\nThe command above reads an XML file at the location specified by `inputFile` and outputs the sorted result to the location specified by `outputFile`. Elements are sorted lexicographically by node name and then by the `\"name\"` attribute, and their attributes are sorted lexicographically by name.\n\nIf `outputFile` is not specified, output goes to stdout; if `inputFile` is also not specified, input is taken from stdin.\n\nExample:\n\n```\njava -cp lp-multisorter.jar XMLSorter file.xml file_sorted.xml\n```\n\nExample with a Unix pipeline:\n\n```\ncat file.xml | java -cp lp-multisorter.jar XMLSorter \u003e file_sorted.xml\n```\n\n### Programmatic Usage\nConstruct a `SortXMLEngine`:\n\n```java\nSortXMLEngine engine = new SortXMLEngine();\n```\n\nBy default, `ElementComparator` is used to order elements, which sorts lexicographically by node name and then by the `\"name\"` attribute, and `AttributeComparator` is used to order attributes, which sorts lexicographically by attribute name.\n\nTo specify a custom order, pass two more arguments to the constructor: a `Comparator` for `ElementVO` objects and a `Comparator` for `ElementAttribute` objects. Use `ElementComparator.MAINTAIN_ORDER` to keep the original order of elements in the file and `AttributeComparator.MAINTAIN_ORDER` to keep the original order of attributes on each element.\n\n```java\nSortXMLEngine engine = new SortXMLEngine(elementComparator, attributeComparator);\n```\n\nThen, call `sort` with an `InputStream` to read the file from and an `OutputStream` to write the sorted result to.\n\n```java\nengine.sort(new FileInputStream(\"file.xml\"), new FileOutputStream(\"file_sorted.xml\"));\n```\n\n## JSON\n### Command Line Usage\n```\njava -cp lp-multisorter.jar JSONSorter [inputFile] [outputFile]\n```\nThis reads a JSON file at the location specified by inputFile and writes the sorted result to the location specified by outputFile. The sorting is done by rearranging all the keys in each object in lexicographic order. Elements of arrays are not moved around.\n\nIf `outputFile` is not specified, output goes to stdout; if `inputFile` is also not specified, input is taken from stdin.\n\n### Programmatic Usage\nConstruct a `SortJSONEngine`. An optional `Comparator\u003cString\u003e` can be specified as the first argument to order the keys in each object. By default, the engine sorts keys in lexicographic order.\n\n```java\nSortJSONEngine engine = new SortJSONEngine();\n```\n\nThen, call `sort` with an `InputStream` and an `OutputStream`.\n\n```java\nengine.sort(new FileInputStream(\"file.json\"), new FileOutputStream(\"file_sorted.json\"));\n```\n\n`sort` may also be called with a `com.github.openjson.JSONObject` or `com.github.openjson.JSONArray` as the only argument, which will sort the keys of all objects in the structure in place.\n\n```java\nJSONObject obj = new JSONObject(\"{\\\"b\\\":1,\\\"a\\\":2}\");\nengine.sort(obj);\n```\n\n## OpenAPI JSON\nLike with XML, Lt. Peacock's Multisorter can be used to sort OpenAPI JSON for easy comparison, especially for large files.\n\n### Command Line Usage\n```\njava -cp lp-multisorter.jar OpenApiJSONSorter [inputFile] [outputFile]\n```\nThe command above reads an OpenAPI JSON file at the location specified by `inputFile` and outputs the sorted result to the location specified by `outputFile`.\n\nIf `outputFile` is not specified, output goes to stdout; if `inputFile` is also not specified, input is taken from stdin.\n\n### Programmatic Usage\nConstruct a `SortOpenApiJSONEngine`:\n\n```java\nSortOpenApiJSONEngine engine = new SortOpenApiJSONEngine();\n```\n\nThen, call `sort` with an `InputStream` to read the file from and an `OutputStream` to write the sorted result to.\n\n```java\nengine.sort(new FileInputStream(\"file.json\"), new FileOutputStream(\"file_sorted.json\"));\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flieutenantpeacock%2Flp-multisorter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flieutenantpeacock%2Flp-multisorter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flieutenantpeacock%2Flp-multisorter/lists"}