Using an incoming string like list:
[{"FECHA":"2019-01-28 13:15:42","SERIAL":2,"LONGITUD":-4.2958984375,"LATITUD":50.4469470596,"ID":1,"VALOR":193,"JOURNEYID":1},
{"FECHA":"2019-01-28 13:15:44","SERIAL":3,"LONGITUD":-4.2958984375,"LATITUD":40.4469470596,"ID":1,"VALOR":34,"JOURNEYID":1},
{"FECHA":"2019-01-28 13:15:46","SERIAL":6,"LONGITUD":-3.2958984375,"LATITUD":50.4469470596,"ID":1,"VALOR":14,"JOURNEYID":1},<..>]
With a lenght N and each element with the following format:
{"FECHA":"2019-01-28 13:15:42","SERIAL":2,"LONGITUD":-4.2958984375,"LATITUD":50.4469470596,"ID":1,"VALOR":193,"JOURNEYID":1}
What I want?
Iterate the list and process each JSON elem individually
first output: {"FECHA":"2019-01-28 13:15:42","SERIAL":2,"LONGITUD":-4.2958984375,"LATITUD":50.4469470596,"ID":1,"VALOR":193,"JOURNEYID":1}
second output: {"FECHA":"2019-01-28 13:15:44","SERIAL":3,"LONGITUD":-4.2958984375,"LATITUD":40.4469470596,"ID":1,"VALOR":34,"JOURNEYID":1}
<...>
How could I split to take each JSON element?
What I have tried:
Option 1:
def ParseIncomingDataAzure(message):
print ("incoming data: {}".format(message))
x = ast.literal_eval(message)
for frame in x:
print("x: {}".format(frame))
Output:
x: {'LATITUD': 50.4469470596, 'FECHA': '2019-01-28 13:15:42', 'JOURNEYID': 1, 'VALOR': 193, 'SERIAL': 2, 'ID': 1, 'LONGITUD': -4.2958984375}
x: {'LATITUD': 40.4469470596, 'FECHA': '2019-01-28 13:15:44', 'JOURNEYID': 1, 'VALOR': 34, 'SERIAL': 3, 'ID': 1, 'LONGITUD': -4.2958984375}
x: {'LATITUD': 50.4469470596, 'FECHA': '2019-01-28 13:15:46', 'JOURNEYID': 1, 'VALOR': 14, 'SERIAL': 6, 'ID': 1, 'LONGITUD': -3.2958984375}
Option 2:
def ParseIncomingDataAzure(message):
messages = message.split(",")
for frame in messages:
print("x: {}".format(frame))
Output:
x: [{"FECHA":"2019-01-28 13:15:42"
x: "SERIAL":2
x: "LONGITUD":-4.2958984375
x: "LATITUD":50.4469470596
x: "ID":1
x: "VALOR":193
x: "JOURNEYID":1}
x: {"FECHA":"2019-01-28 13:15:44"
x: "SERIAL":3
x: "LONGITUD":-4.2958984375
x: "LATITUD":40.4469470596
x: "ID":1
x: "VALOR":34
x: "JOURNEYID":1}
x: {"FECHA":"2019-01-28 13:15:46"
x: "SERIAL":6
x: "LONGITUD":-3.2958984375
x: "LATITUD":50.4469470596
x: "ID":1
x: "VALOR":14
x: "JOURNEYID":1}]
Option 3:
Simple for to iterate over the list
def ParseIncomingDataAzure(message):
for frame in message:
print("x: {}".format(frame))
Output:
x: [
x: {
x: "
x: F
x: E
x: C
x: H
x: A
<....>
Possible solution:
def ParseIncomingDataAzure(message):
print ("incoming data: {}".format(message))
x = ast.literal_eval(message)
for frame in x:
print("x: {}".format(json.dumps(frame)))
Is this the correct way?
forloop to iterate over them?