Michael Müller
02 Mar, 2023

SemanticDiff 0.8.2: JSON Support And More

The second beta release of SemanticDiff adds support for comparing JSON files, can hide more irrelevant changes, and fixes several minor bugs. Find out how you can benefit from the changes.

We just released a new beta version of SemanticDiff (0.8.2) and want to give you a quick overview of the changes:

  • Add initial support for diffing JSON(5) files
  • Add support for diffing two unsaved files
  • Add entry in the action menu to re-compute the currently opened semantic diff
  • Ignore insertion/deletion of parentheses when they have no effect
  • Fix missing syntax highlighting for various third-party themes
  • Fix breadcrumbs when using SemanticDiff with GitLens
  • Improve language detection
  • Improve moved line detection
  • Improve detection of file encoding

Two of the changes are explained in more details below.

VS Code will automatically download and update SemanticDiff to the latest version and no action should be required. If not, you can get the latest packages from the Visual Studio Marketplace:

Download Beta

JSON(5) Support

SemanticDiff 0.8.2 adds support for the data exchange format JSON5, which is a superset of the “standard” JSON defined by ECMA-404. Notable about this addition is that we do not only have support for ignoring minor syntactical changes. Since the JSON specification defines an object as an unordered collection, SemanticDiff will also ignore reordering of key-value pairs within the same object.

While implementing the reordering detection in the diff algorithm was straightforward, handling its visual representation was a bit trickier. We didn’t want to show a move indicator for a move that was essentially a no-op. We also didn’t want to show an empty line on one side of the diff while the other side contains a value, as this looks like a bug. We eventually decided to align the old lines in the diff with the new lines, so that matching lines are always shown side by side:

Swapped key-value pair in JSON file

What this means in practice is that the lines of the old diff may appear out of order if a key-value pair has been moved. The screenshot shows such an example where the key a has been moved from line 2 to 4. We hope that you will find this to be the most helpful solution as well. Otherwise let us know.

Insertion and Deletion of Parentheses

Parentheses have a big impact on the correctness of a calculation. But figuring out whether adding or removing them makes a real difference can sometimes be tricky. For example, do you know by heart whether the following two Python snippets produce identical results?

x = 1 + 2 << 3 | 0xff00 % 100
x = ((1 + 2) << 3) | (0xff00 % 100)

SemanticDiff 0.8.2 will help you find out. Insertions and deletions of parentheses are no longer shown as changes if they have no effect. At least if there aren’t any other changes on the same line.

We added this restriction because we found the magical appearance and disappearance of parentheses combined with other changes to be a bit confusing. Let’s take the code change from 1+2 to (1+2)*3 as an example. The added parentheses are technically irrelevant without the added multiplication and one could argue that only the *3 part should be shown as change.

To stay closer to a traditional diff, SemanticDiff will still indicate the added parentheses if they are combined with other changes, but we are always open to feedback.

[Solution for the Python example: Both snippets are identical. The priority of the used operators is % > + > << > | and therefore match the added parentheses.]

We hope you enjoyed this update!

Recent Articles

SemanticDiff vs. Difftastic: How do they differ?
SemanticDiff vs. Difftastic: How do they differ?

Both tools aim to provide a better diff, but which one fits your needs? We compared their inner workings, features, and workflow integration to help you decide.

Read More
Unicode tricks in pull requests: Do review tools warn us?
Unicode tricks in pull requests: Do review tools warn us?

How well do GitHub, GitLab and Bitbucket support reviewers in finding malicious code changes in pull requests? Let’s give it a test.

Read More
SemanticDiff 0.8.8: Support For Rust And More
SemanticDiff 0.8.8: Support For Rust And More

The eight beta release of our VS Code extension / GitHub App SemanticDiff adds support for Rust, new invariances and other enhancements.

Read More