Skip to content

[Feedback] JSON display mode schema #916

@lmmx

Description

@lmmx

I'd really like to see some usage feedback of the JSON output, to confirm that the current design makes sense for external consumers.

$ DFT_UNSTABLE=yes DFT_DISPLAY=json difft before.js after.js

(No-one has complained yet about DFT_UNSTABLE being required, so I'm not sure anyone is actually using this output option right now.)

via #216 (comment)

I was just trying this out and thought I ought drop in with some of the requested feedback.

So, very nice, but the pedant in me wants to note it is actually JSONL (or NDJSON) specifically :)

If I run it through genson-cli I get the following schema (posted more just in case it's useful to others), like this:

DFT_DISPLAY=json DFT_UNSTABLE=yes git -c diff.external=difft diff --cached | genson-cli --ndjson
Click to show JSON schema (not comprehensive!)
{
  "$schema": "http://json-schema.org/schema#",
  "properties": {
    "chunks": {
      "type": "array",
      "items": {
        "type": "array",
        "items": {
          "properties": {
            "rhs": {
              "properties": {
                "line_number": {
                  "type": "integer"
                },
                "changes": {
                  "type": "array",
                  "items": {
                    "properties": {
                      "start": {
                        "type": "integer"
                      },
                      "end": {
                        "type": "integer"
                      },
                      "content": {
                        "type": "string"
                      },
                      "highlight": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "content",
                      "end",
                      "highlight",
                      "start"
                    ],
                    "type": "object"
                  }
                }
              },
              "required": [
                "changes",
                "line_number"
              ],
              "type": "object"
            }
          },
          "required": [
            "rhs"
          ],
          "type": "object"
        }
      }
    },
    "language": {
      "type": "string"
    },
    "path": {
      "type": "string"
    },
    "status": {
      "type": "string"
    }
  },
  "required": [
    "language",
    "path",
    "status"
  ],
  "type": "object"
}

The schema for a file with edits and the schema for a file freshly created is completely different, so the chunks field is not required (for files that are newly created).

Feedback from me is this is very useful, and that this is pretty much perfect for my use. Perhaps uptake of the library can be assisted by sharing the expected JSON format (using a JSON schema or example de/ser structs). For what it's worth the branch I'm working on implementing difftastic as a format on can be found here: lmmx/asterism#12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions