Search code examples
pythonjsonstringtransformationreal-time-data

In python get max value on lookup of byte array substring


I am using python3. Below is my sample data b'{"receivedTimestamp":1604484102747,"application":"MMT","messageType":"BusEvent","utcTimestamp":1604484102711,"data":[{"id":56476901531}]}{"receivedTimestamp":1604484102748,"application":"MMT","messageType":"BusEvent","utcTimestamp":1604484102711,"data":[{"id":56476901532}]}'

In python above data is treated as byte array I guess

Explanation of data If we observe there are 2 json messages each json message tag is starting with receivedTimestamp

What I need ? I need to find the maximum of timestamp of these two message it should return me value 1604484102748, as this is greater .

I am struggling to parse this message. Request anyone to parse this data or point me in right direction to frame the code and get the intended value in python.

Thanx in advance


Solution

  • tmp = str(my_json)
    i = tmp.rfind('receivedTimestamp') # index of last appearance receivedTimestamp
    i = i-2 #index between jsons
    first_json = json.loads(tmp[2:i])
    second_json = json.loads(tmp[i:-1])