@@ -15,11 +15,15 @@ <h1>JSON Diff Demo</h1>
15
15
< div class ="flex-row ">
16
16
< div class ="width-half ">
17
17
< h2 > Text Version 1:</ h2 >
18
- < textarea id ="text1 " class ="width-full " rows ="10 "> {"Aidan Gillen": {"array": ["Game of Thron\"es","The Wire"],"string": "some string","int": 2,"aboolean": true, "boolean": true,"object": {"foo": "bar","object1": {"new prop1": "new prop value"},"object2": {"new prop1": "new prop value"},"object3": {"new prop1": "new prop value"},"object4": {"new prop1": "new prop value"}}},"Amy Ryan": {"one": "In Treatment","two": "The Wire"},"Annie Fitzgerald": ["Big Love","True Blood"],"Anwan Glover": ["Treme","The Wire"],"Alexander Skarsgard": ["Generation Kill","True Blood"], "Clarke Peters": null}</ textarea >
18
+ < textarea id ="text1 " class ="width-full "
19
+ rows ="10 "> {"Aidan Gillen": {"array": ["Game of Thron\"es","The Wire"],"string": "some string","int": 2,"aboolean": true, "boolean": true,"object": {"foo": "bar","object1": {"new prop1": "new prop value"},"object2": {"new prop1": "new prop value"},"object3": {"new prop1": "new prop value"},"object4": {"new prop1": "new prop value"}}},"Amy Ryan": {"one": "In Treatment","two": "The Wire"},"Annie Fitzgerald": ["Big Love","True Blood"],"Anwan Glover": ["Treme","The Wire"],"Alexander Skarsgard": ["Generation Kill","True Blood"], "Clarke Peters": null}</ textarea >
20
+ < label id ="text1-error " for ="text1 " class ="error "> </ label >
19
21
</ div >
20
22
< div class ="width-half ">
21
23
< h2 > Text Version 2:</ h2 >
22
- < textarea id ="text2 " class ="width-full " rows ="10 "> {"Aidan Gillen": {"array": ["Game of Thrones","The Wire"],"string": "some string","int": "2","otherint": 4, "aboolean": "true", "boolean": false,"object": {"foo": "bar"}},"Amy Ryan": ["In Treatment","The Wire"],"Annie Fitzgerald": ["True Blood","Big Love","The Sopranos","Oz"],"Anwan Glover": ["Treme","The Wire"],"Alexander Skarsg?rd": ["Generation Kill","True Blood"],"Alice Farmer": ["The Corner","Oz","The Wire"]}</ textarea >
24
+ < textarea id ="text2 " class ="width-full "
25
+ rows ="10 "> {"Aidan Gillen": {"array": ["Game of Thrones","The Wire"],"string": "some string","int": "2","otherint": 4, "aboolean": "true", "boolean": false,"object": {"foo": "bar"}},"Amy Ryan": ["In Treatment","The Wire"],"Annie Fitzgerald": ["True Blood","Big Love","The Sopranos","Oz"],"Anwan Glover": ["Treme","The Wire"],"Alexander Skarsg?rd": ["Generation Kill","True Blood"],"Alice Farmer": ["The Corner","Oz","The Wire"]}</ textarea >
26
+ < label id ="text2-error " for ="text2 " class ="error "> </ label >
23
27
</ div >
24
28
</ div >
25
29
< h3 > Diff timeout:</ h3 >
@@ -70,11 +74,25 @@ <H3>Post-diff cleanup:</H3>
70
74
function launch ( ) {
71
75
const text1 = document . getElementById ( 'text1' ) . value
72
76
const text2 = document . getElementById ( 'text2' ) . value
77
+ let object1 = null
78
+ let object2 = null
79
+ try {
80
+ object1 = JSON . parse ( text1 )
81
+ } catch ( error ) {
82
+ document . getElementById ( 'text1-error' ) . innerText = 'Parse Text Version 1 error: ' + error
83
+ throw ( 'Parse Text Version 1 error: ' + error )
84
+ }
85
+ try {
86
+ object2 = JSON . parse ( text2 )
87
+ } catch ( error ) {
88
+ document . getElementById ( 'text2-error' ) . innerText = 'Parse Text Version 2 error: ' + error
89
+ throw ( 'Parse Text Version 2 error: ' + error )
90
+ }
73
91
dmp . Diff_Timeout = parseFloat ( document . getElementById ( 'timeout' ) . value )
74
92
dmp . Diff_EditCost = parseFloat ( document . getElementById ( 'edit-cost' ) . value )
75
93
76
94
const msStart = ( new Date ( ) ) . getTime ( )
77
- const d = dmp . diff_main ( text1 , text2 )
95
+ const d = dmp . diff_main ( JSON . stringify ( object1 , null , 2 ) , JSON . stringify ( object2 , null , 2 ) )
78
96
const msEnd = ( new Date ( ) ) . getTime ( )
79
97
80
98
if ( document . getElementById ( 'semantic' ) . checked ) {
0 commit comments