F# how to serialize records to nested JSon data

  • Thread starter Thread starter zydjohn
  • Start date Start date
Z

zydjohn

Guest
If I have some records in F#:

type Coureur=
{ runner_name: string
distance : string
unit : string
score: float }

let stoppage =
seq [
{ runner_name= "No 1" ; distance = "100M"; unit = "seconds"; score = 10.0}
{ runner_name= "No 2" ; distance = "200M"; unit = "seconds"; score = 20.0}
]

I want to serialize the records to the nested Json data, like the following:

{

"sports": {

"measure-type": "Metric",

"runner-type": "track-field",

"runners": [

{

"runner-name":"No 1" , "distance": "100M", "unit": "seconds", "score": 10.0

},{

"runner-name":"No 2" , "distance": "200M", "unit": "seconds", "score": 20.0

}]

}


The top part of the JSon data is fixed, only the nested part of “runners” are from the records in the above code.

I can’t find good example to do this, which one I should use?

DataContract or JSon type provider?

Please advise.

Thanks,

Continue reading...
 
Back
Top