Jamie Dixon
Jamie Dixon

Reputation: 4292

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

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

Upvotes: 6

Views: 477

Answers (1)

Tomas Petricek
Tomas Petricek

Reputation: 243051

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).

Upvotes: 12

Related Questions