Representing JSON Separator Change in diff3x

The problem with separators is that they cannot consistently be associated with either the start or the end of each item (member for object and value for array) because if there is only one item then no separator is needed. Therefore maintaining correct syntax when items are added or deleted is not trivial. As mentioned above, the diff3 format does not allow consecutive choices without 'anchor' data between, so it is necessary to group consecutive items that may be added or deleted into one choice. This apparent restriction does lead to a greater likelihood of the syntax of each choice being consistent.

Here is an example of a change to an array of strings.

Table 4. JSON array value change

["one", "two"]
["three", "four"]

This could be represented as shown below. Note here that we are not showing the result of running 'diff3 -m' but rather we have run an XML aware comparison so we have results that we want to express in the diff3 format.

<<<<<<< A.txt
"one", "two"
||||||| O.txt
"three", "four"
>>>>>>> B.txt

The above will produce syntactically correct results though it is not ideal because it would be more natural to choose the values separately rather than as a complete list. This can be achieved with diff3x as shown below. Here we have been able to perform the merge automatically, there are no conflicts but clearly it is useful for the user to see these and have the option to undo or change a choice.

We introduce here a third type of choice, the <autoInclude>. This is a choice that we do not expect the user to review but rather it is a single option that is chosen automatically based on one or more other selections. In this case, the commas are inserted only when they are needed.

<diff3x a="A.txt" b="B.txt" o="O.txt">
  <ao id="ao42">"one"</ao>
  <b id="b44" include="true"></b></choice2>
<autoInclude select="AND(ao42 a52)">, </autoInclude>
  <a id="a52" include="true">"two"</a>
  <ob id="ob53"></ob></choice2>
<autoInclude select="AND(OR(ao42 a52) b62)">, </autoInclude>
  <b id="b62" include="true">"three", "four"</b>
  <ao id="ao63"></ao></choice2>

Result of this choice is:
["two", "three", "four"]

This is more complex in getting the logic correct for insertion of commas. XML users will be pleased that XML attributes are not comma separated!