Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json Type Provider: using type as an argument in a function

Tags:

f#

f#-data

I have a json document like this:

{ "index": 1, "addressOne": "1506 WAKE FOREST RD ", "addressTwo": "RALEIGH NC 27604-1331", "addressThree": " ", "assessedValue": "$34,848", "id": "c0e931de-68b8-452e-8365-66d3a4a93483", "_rid": "pmVVALZMZAEBAAAAAAAAAA==", "_ts": 1423934277, "_self": "dbs/pmVVAA==/colls/pmVVALZMZAE=/docs/pmVVALZMZAEBAAAAAAAAAA==/", "_etag": "\"0000c100-0000-0000-0000-54df83450000\"", "_attachments": "attachments/" }

I then load it via the type provider like this:

type HouseValuation = JsonProvider<"../data/HouseValuationSample.json">

When I try and use the HouseValuation as part of an argument, it is cast back to Object:

enter image description here

What am I doing wrong?

Thanks in advance

like image 759
Jamie Dixon Avatar asked Feb 14 '15 17:02

Jamie Dixon


1 Answers

The type HouseValuation is a root type that is used just to host the Parse and Load methods, but it is not a type that represents the actual parsed document. If you look at the type of Load or Parse, you'll see something like this:

Load : string -> JsonProvider<"...">.Root

So, the type of the actual parsed document is a nested type Root under the main provided type HouseValuation. The function should then take HouseValuation.Root as argument instead:

type HouseValuation = JsonProvider<" ... ">

let createSchoolAssignmentSearchCriteria(houseValuation:HouseValuation.Root) = 
  houseValuation.AddressOne

When you type HouseValuation. you'll see the two static methods and also all the nested types there (though in this example, there is only one record type).

like image 146
Tomas Petricek Avatar answered Nov 15 '22 11:11

Tomas Petricek