Json Type Provider : parsing misbehaving data

92 Views Asked by At

I am processing messages. Each message corresponds to a coordinate, and MOST of the coordinates are in a specific JSON form. Problem is, some naughty messages have the wrong format (a different format, where a whole list of coordinates comes in one message).

Ideally, I would like to process both types of message, but the built-in Parse function for JsonProvider seems to succeed even when the incoming data is in the wrong format. How can I know in advance (before attempting to parse) what format my datum is in?

My two data models look something like this:

type ModelA = JsonProvider<"""{      
  "id": "13222",
  "timestamp": 1499329186332.0,
  "latitude": 12.125419,
  "longitude": 15.054884
 }""">

type ModelB = JsonProvider<"""{
    "data": {

        "positions": [
          {      
           "id": "13223",
           "timestamp": 1499329186332.0,
           "latitude": 12.125419,
           "longitude": 15.054884
          },
         {      
           "id": "13223",
           "timestamp": 1499329186332.0,
           "latitude": 12.125419,
           "longitude": 15.054884
         }]
    } 
}""">
0

There are 0 best solutions below