I have a PHP application where I receive two different JSON responses from two different tools. However, I want to utilize the same JavaScript code to handle both responses.
My goal is to compare the following data structures:
data = [
{'k1':'v1'},
{'k2':'v2'},
{'k3':'v3'}
]
with this one:
data = {'k11':'v11', 'k22':'v22', 'k33':'v33'}
This comparison should be able to handle any number of results and should still work if only one result is present in either case.
I have already attempted - using data.length (assuming it would return an array with one element for the second case) - data instanceof Array, which is true for both cases (same goes for data instanceof Object)
What is the most effective approach to comparing these structures in JavaScript?
EDITED: The keys and values of both JSON objects do not need to match; I simply want to compare their structure or detect one without having the other (an array of objects vs an object with properties).