JsonInlineFormatter 0.2.0

dotnet tool install --global JsonInlineFormatter --version 0.2.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local JsonInlineFormatter --version 0.2.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=JsonInlineFormatter&version=0.2.0
                    
nuke :add-package JsonInlineFormatter --version 0.2.0
                    

JsonInlineFormatter

[ English | 中文 ]

A tool for quickly mixed-formatting JSON.
It can be used to format certain JSON fields into a single line or multiple lines to improve readability and maintainability.
Field alignment has been added for arrays of arrays and arrays of objects.

Usage

jsonInlineFormatter <command> [arguments]

format

jsonInlineFormatter format <input_file> <output_file> [format]

<input_file>: Input JSON file path <output_file>: Output JSON file path <format>: Specify the fields to be formatted\

  • Single match rule:
    • . represents an object node
    • property represents a property of an object node
    • * represents any property of an object node
    • [0] represents the first element of an array node
    • [*] represents all elements of an array node
    • // added as prefix disables the parsing of this rule (for debugging)

    This syntax is different from JSONPath or JMESPath.

  • Multiple match rules:
    Use ; or a line break to separate multiple matching rules, for example: .property1;property2[*].subProperty Shorter rules will take precedence for matching, for example: . will match before .property1.
  • Indentation:
    When using multiple matching rules, use whitespace characters at the beginning of the matching rule and separate them to indicate the indent character and amount,
    for example: ;.property1;property2[*].subProperty indicates using two spaces for indentation in multi-line mode.

You can use . to directly compact the entire JSON file, or provide no rules to keep the default JSON formatting.

diff

jsonInlineFormatter diff <left_file> <right_file> [ordered_paths] [--tolerance <value>]

<left_file>: First JSON file path
<right_file>: Second JSON file path
<ordered_paths>: The paths that should be compared in order (optional)

Compares two JSON files and writes a structured JSON report to standard output, so it composes well with scripts:

{
  "equal": false,
  "changeCount": 2,
  "changes": [
    { "path": ".name", "kind": "changed", "left": "Alice", "right": "Bob" },
    { "path": ".tags", "kind": "added", "right": ["new"] }
  ]
}

By default both object key order and array element order are ignored, so {"a":1,"b":2} equals {"b":2,"a":1} and [1,2,3] equals [3,2,1]. Unordered arrays are compared as multisets: elements that are equal under these rules cancel out, and the leftovers are reported as removed / added.

<ordered_paths> uses the same path syntax as format. A node whose path is listed is compared in order — objects by key order, arrays by element order — and the rule does not flow down: descendants of that node go back to unordered comparison unless they are listed by their own path. For example .items makes the items array ordered, and .items[*] additionally makes the key order of each element object significant. A trailing [*] also designates the array node itself, matching how .roles[*] refers to the roles array in format.

--tolerance <value> (alias -t) treats two numbers as equal when their absolute difference is at most <value> (default 0, i.e. exact equality). The tolerance also participates in matching the items of unordered arrays, so slightly different floats do not turn a pair into removed / added; because this equality is not transitive, unordered matching is greedy and takes the first available candidate.

kind is one of added, removed, changed, or keyOrder (the ordered keys differ while the set of keys is the same).

Exit codes: 0 when the documents are equal, 1 when they differ, 2 on error.

Example

{"name":"Alice","age":30,"email":"alice@example.com","aliases":["Ally","Alicia"],"roles":["developer","admin"],"active":true,"score":{"SUB_A":98.5,"SUB_B":88.0,"SUB_C":95.5},"profile":{"bio":"Software developer with 10 years of experience.","interests":["coding","hiking","cooking"],"social":{"twitter":"@alice","linkedin":"alice-chen"}},"actions":[{"type":"login","ip":"203.0.113.1","timestamp":"2026-05-21T09:00:00Z"},{"type":"deploy","timestamp":"2026-05-21T14:30:00Z"},{"type":"meeting","timestamp":"2026-05-21T16:00:00Z","participants":["Bob","Carol"]},{"type":"logout","timestamp":"2026-05-21T18:00:00Z","ip":"203.0.113.1"}],"skillsMatrix":[["js","python","go"],["mysql","mongodb"],["aws","gcp"]],"projects":[{"id":1,"name":"API GW","status":"active","team":["Bob","Carol","Dave"],"milestones":[{"phase":"design","complete":true},{"phase":"dev","complete":false},{"phase":"test","complete":false}],"dependencies":[2,3]},{"id":2,"name":"Pipeline","status":"done","team":["Alice"],"milestones":[],"dependencies":[]}]}
jsonInlineFormatter format example.json out.json "  ;
.aliases
.roles[*]
.score
.profile.
.actions[*].
.skillsMatrix[*][*]
.projects[*].*[*]"

Example Output:

{
  "name": "Alice",
  "age": 30,
  "email": "alice@example.com",
  "aliases": ["Ally","Alicia"],
  "roles": 
    ["developer","admin"],
  "active": true,
  "score": {"SUB_A":98.5,"SUB_B":88.0,"SUB_C":95.5},
  "profile": 
    {"bio":"Software developer with 10 years of experience.","interests":["coding","hiking","cooking"],"social":{"twitter":"@alice","linkedin":"alice-chen"}},
  "actions": [
    {"type":"login",  "ip":"203.0.113.1","timestamp":"2026-05-21T09:00:00Z"},
    {"type":"deploy",                    "timestamp":"2026-05-21T14:30:00Z"},
    {"type":"meeting",                   "timestamp":"2026-05-21T16:00:00Z","participants":["Bob","Carol"]},
    {"type":"logout", "ip":"203.0.113.1","timestamp":"2026-05-21T18:00:00Z"}
  ],
  "skillsMatrix": [
    ["js",   "python", "go"],
    ["mysql","mongodb"],
    ["aws",  "gcp"]
  ],
  "projects": [
    {
      "id": 1,
      "name": "API GW",
      "status": "active",
      "team": 
        ["Bob","Carol","Dave"],
      "milestones": 
        [{"phase":"design","complete":true},{"phase":"dev","complete":false},{"phase":"test","complete":false}],
      "dependencies": 
        [2,3]
    },
    {
      "id": 2,
      "name": "Pipeline",
      "status": "done",
      "team": 
        ["Alice"],
      "milestones": 
        [],
      "dependencies": 
        []
    }
  ]
}

In this example,

  • The aliases and profile fields are on the same line as the field name.
  • The roles and score fields start on a new line.
  • Each identical sub-field of the objects under the actions field is aligned in the same column.
  • The array elements under the skillsMatrix field are aligned in the same column by index.
  • Each array element field of the object array under the projects field is inline compressed into a single line.
  • The other parts are formatted using the default JSON format, indented by two spaces.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.2.0 160 9/29/2026
0.1.0 156 5/22/2026