spicykimchi
spicykimchi

Reputation: 1151

JSON compare element or existing of an element

How can I find and compare values in json?let say

{"data 1": {
    "product": "54",
    "info": {
        "browser": "Safari",
        "isp": "isp sample",
        "width": 500,
        "ip": 109.24.55.121,
        "uid": 124,
        "location": 10.23,123.90
    }
}
{"data 2": {
    "campaign": "2",
    "info": {
        "browser": "Mozilla",
        "isp": "isp sample",
        "width": 500,
        "ip": 109.24.55.121,
        "uid": 231,
        "location": 10.23,123.90
    }
}
{"data 3": {
    "campaign": "2",
    "info": {
        "browser": "Mozilla",
        "isp": "isp sample",
        "width": 500,
        "ip": 109.24.55.121,
        "uid": 227,
        "location": 10.23,123.90
    }
}
{"same data": {
    "campaign": "2",
    "info": {
        "browser": "Mozilla",
        "isp": "isp sample",
        "width": 500,
        "ip": 109.24.55.121,
        "uid": 227,
        "location": 10.23,123.90
    }
}
{"same data": {
    "campaign": "2",
    "info": {
        "browser": "Mozilla",
        "isp": "isp sample",
        "width": 500,
        "ip": 109.24.55.121,
        "uid": 227,
        "location": 10.23,123.90
    }
}

And I want to output the what are there similarities.on what string and what values.

Upvotes: 0

Views: 551

Answers (1)

Marc B
Marc B

Reputation: 360662

$data = json_decode($your_json_data);

foreach($data as $datum) {
    .... do some processing ...
}

json_encode/json_decode will translate between native PHP arrays and native Javascript arrays/objects. You don't say which language you want to do the processing in, but since JSON IS javascript, there's no decoding to be done on the javascript side. just load up the data and go. On PHP, you'd want to decode it into a native PHP array first.

Upvotes: 1

Related Questions