0

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

Naveen Srikanth
  • 739
  • 3
  • 11
  • 23

1 Answers1

1
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])

trigonom
  • 528
  • 4
  • 9
  • This has helped me thank you . From here I will take it up. In this scenario I know there are 2 json upfront did it .What if I dont know how many messages are coming in . I am working on realtime streaming hence I got this doubt – Naveen Srikanth Nov 10 '20 at 10:12
  • 1
    welcome, if you have an example of more then 2 JSON, i think it can be a generic split without knowing the size – trigonom Nov 10 '20 at 11:30