B4J Question two json string compare

billyrudi

Active Member
Licensed User
Longtime User
Hi,
how i can compare in b4j two json like this in javascript?

var isEqualsJson = (obj1,obj2)=>{
keys1 = Object.keys(obj1);
keys2 = Object.keys(obj2);

//return true when the two json has same length and all the properties has same value key by key
return keys1.length === keys2.length && Object.keys(obj1).every(key=>obj1[key]==obj2[key]);
}

var obj1 = {a:1,b:2,c:3};
var obj2 = {a:1,b:2,c:6};

console.log("json is equals: "+ isEqualsJson(obj1,obj2));
alert("json is equals: "+ isEqualsJson(obj1,obj2));

regards
 
Solution
It looks like a simple (non recursive) Map comparison.
B4X:
Sub AreSimpleMapsEqual(m1 As Map, m2 As Map) As Boolean
If m1.Length <> m2.Length Then Return False
For Each k As Object In m1.Keys
 If m1.Get(k) <> m2.Get(k) Then Return False
Next
Return True
End Sub
Top