I’m trying to convert the below data into JSON using python, eg import json. I had actually originally thought I was receiving JSON data until I echoed it out and found the below.
Unfortunately, I receive the below data from a SOAP service so have no control of how I receive it.
Anyway, does it look like the below has any structure that could be parsed? Or will I have to go through it line by line and manually convert it? It doesnt look like anything I’ve seen before, even though some of the variable names look like they’re XML, or were originally XML.
I’m only interested in the values of the stopData[] array, just over halfway down, if that simplifies things!
For the record, I tried parsing it with a JSON parser as follows, but it did not recognise it:
data = json.loads(rawData)
data['StopData']
I also tried:
data = json.loads(rawData)
but neither worked.
Here’s the data I’ve to work with:
('schema', [(schema){
_id = "NewDataSet"
element[] =
(element){
_UseCurrentLocale = "true"
_IsDataSet = "true"
_MainDataTable = "StopData"
_name = "NewDataSet"
complexType[] =
(complexType){
choice[] =
(choice){
_maxOccurs = "unbounded"
_minOccurs = "0"
element[] =
(element){
_name = "StopData"
complexType[] =
(complexType){
sequence[] =
(sequence){
element[] =
(element){
_type = "xs:dateTime"
_name = "ServiceDelivery_ResponseTimestamp"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "ServiceDelivery_ProducerRef"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "ServiceDelivery_Status"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "ServiceDelivery_MoreData"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "StopMonitoringDelivery_Version"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "StopMonitoringDelivery_ResponseTimestamp"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "StopMonitoringDelivery_RequestMessageRef"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredStopVisit_RecordedAtTime"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredStopVisit_MonitoringRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_LineRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_DirectionRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "FramedVehicleJourneyRef_DataFrameRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "FramedVehicleJourneyRef_DatedVehicleJourneyRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_PublishedLineName"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_OperatorRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_DestinationRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_DestinationName"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "MonitoredVehicleJourney_Monitored"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "MonitoredVehicleJourney_InCongestion"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_BlockRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredVehicleJourney_VehicleRef"
_minOccurs = "0"
},
(element){
_type = "xs:string"
_name = "MonitoredCall_VisitNumber"
_minOccurs = "0"
},
(element){
_type = "xs:boolean"
_name = "MonitoredCall_VehicleAtStop"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredCall_AimedArrivalTime"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredCall_ExpectedArrivalTime"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredCall_AimedDepartureTime"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "MonitoredCall_ExpectedDepartureTime"
_minOccurs = "0"
},
(element){
_type = "xs:dateTime"
_name = "Timestamp"
_minOccurs = "0"
},
},
},
},
},
},
},
}])('diffgram', [(diffgram){
DocumentElement[] =
(DocumentElement){
StopData[] =
(StopData){
_id = "StopData1"
_rowOrder = "0"
ServiceDelivery_ResponseTimestamp[] =
"2013-01-21T20:57:40.33+00:00",
ServiceDelivery_ProducerRef[] =
"bac",
ServiceDelivery_Status[] =
"true",
ServiceDelivery_MoreData[] =
"false",
StopMonitoringDelivery_Version[] =
"1.0",
StopMonitoringDelivery_ResponseTimestamp[] =
"2013-01-21T20:57:40.333+00:00",
StopMonitoringDelivery_RequestMessageRef[] =
"0",
MonitoredStopVisit_RecordedAtTime[] =
"2013-01-21T20:57:40.333+00:00",
MonitoredStopVisit_MonitoringRef[] =
"02371",
MonitoredVehicleJourney_LineRef[] =
"27",
MonitoredVehicleJourney_DirectionRef[] =
"Inbound",
FramedVehicleJourneyRef_DataFrameRef[] =
"2013-01-21",
FramedVehicleJourneyRef_DatedVehicleJourneyRef[] =
"4215",
MonitoredVehicleJourney_PublishedLineName[] =
"77A",
MonitoredVehicleJourney_OperatorRef[] =
"bac",
MonitoredVehicleJourney_DestinationRef[] =
"00354",
MonitoredVehicleJourney_DestinationName[] =
"Ringsend Rd via Tymon Park",
MonitoredVehicleJourney_Monitored[] =
"true",
MonitoredVehicleJourney_InCongestion[] =
"false",
MonitoredVehicleJourney_BlockRef[] =
"027023A:34",
MonitoredVehicleJourney_VehicleRef[] =
"33521",
MonitoredCall_VisitNumber[] =
"39",
MonitoredCall_VehicleAtStop[] =
"false",
MonitoredCall_AimedArrivalTime[] =
"2013-01-21T21:21:00+00:00",
MonitoredCall_ExpectedArrivalTime[] =
"2013-01-21T21:20:12+00:00",
MonitoredCall_AimedDepartureTime[] =
"2013-01-21T21:21:00+00:00",
MonitoredCall_ExpectedDepartureTime[] =
"2013-01-21T21:20:12+00:00",
Timestamp[] =
"2013-01-21T20:57:40.627+00:00",
},
(StopData){
_id = "StopData2"
_rowOrder = "1"
ServiceDelivery_ResponseTimestamp[] =
"2013-01-21T20:57:40.33+00:00",
ServiceDelivery_ProducerRef[] =
"bac",
ServiceDelivery_Status[] =
"true",
ServiceDelivery_MoreData[] =
"false",
StopMonitoringDelivery_Version[] =
"1.0",
StopMonitoringDelivery_ResponseTimestamp[] =
"2013-01-21T20:57:40.333+00:00",
StopMonitoringDelivery_RequestMessageRef[] =
"0",
MonitoredStopVisit_RecordedAtTime[] =
"2013-01-21T20:57:40.333+00:00",
MonitoredStopVisit_MonitoringRef[] =
"02371",
MonitoredVehicleJourney_LineRef[] =
"27",
MonitoredVehicleJourney_DirectionRef[] =
"Inbound",
FramedVehicleJourneyRef_DataFrameRef[] =
"2013-01-21",
FramedVehicleJourneyRef_DatedVehicleJourneyRef[] =
"4061",
MonitoredVehicleJourney_PublishedLineName[] =
"77A",
MonitoredVehicleJourney_OperatorRef[] =
"bac",
MonitoredVehicleJourney_DestinationRef[] =
"00354",
MonitoredVehicleJourney_DestinationName[] =
"Ringsend Rd via Tymon Park",
MonitoredVehicleJourney_Monitored[] =
"true",
MonitoredVehicleJourney_InCongestion[] =
"false",
MonitoredVehicleJourney_BlockRef[] =
"027008:34",
MonitoredVehicleJourney_VehicleRef[] =
"33204",
MonitoredCall_VisitNumber[] =
"39",
MonitoredCall_VehicleAtStop[] =
"false",
MonitoredCall_AimedArrivalTime[] =
"2013-01-21T21:44:00+00:00",
MonitoredCall_ExpectedArrivalTime[] =
"2013-01-21T21:44:00+00:00",
MonitoredCall_AimedDepartureTime[] =
"2013-01-21T21:44:00+00:00",
MonitoredCall_ExpectedDepartureTime[] =
"2013-01-21T21:44:00+00:00",
Timestamp[] =
"2013-01-21T20:57:40.627+00:00",
},
},
}])
For the record, I fixed this by using code like this:
This showed me that the data is actually stored in a multi-dimensional array. When I put that into python, it creates an array (although when I output it [data=list], it told me it cant concatenate a string and a list).
But anyway, I can now access individual elements of data using arrays.
Cheers.