Json type provider: using a type as an argument in a function

I have a json document:

{"index": 1, "addressOne": "1506 WAKE FOREST RD", "addressTwo": "RALEIGH NC 27604-1331", "addressThree": "," ratedValue ":" $ 34.848 "," id ":" c0e931de -68b8-452e-8365-66d3a4a93483 "," _rid ":" pmVVALZMZAEBAAAAAAAAAAA == "," _ts ": 1423934277, msgstr" msgstr "" _attachments ":" attachments / "}

Then I load it through the type provider as follows:

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

When I try to use HouseValuation as part of an argument, it returns to Object:

enter image description here

What am I doing wrong?

Thank you in advance

+6
source share
1 answer

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

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

Thus, the type of the actual parsed document is a nested Root type in the main HouseValuation type HouseValuation . Then the function should take HouseValuation.Root as an argument:

 type HouseValuation = JsonProvider<" ... "> let createSchoolAssignmentSearchCriteria(houseValuation:HouseValuation.Root) = houseValuation.AddressOne 

When entering HouseValuation. you will see two static methods, as well as all nested types (although in this example there is only one record type).

+10
source

Source: https://habr.com/ru/post/982494/


All Articles