The JsonProvider
can be viewed as a parametrized JSON parser (plus the data type that the parser produces) that is specialized at compile time.
The parameter you give to it (a string or a path to JSON file) defines the structure of JSON data -- a schema if you wish. This allows the provider to create a type that will have all the properties your JSON data should have, statically, and the set of those properties (along with their respective types) are defined (actually inferred from) with the JSON sample that you give to the provider.
So the correct way to use the JsonProvider
is shown in one of the examples from the documentation:
// generate the type with a static Parse method with help of the type provider
type Simple = JsonProvider<""" { "name":"John", "age":94 } """>
// call the Parse method to parse a string and create an instance of your data
let simple = Simple.Parse(""" { "name":"Tomas", "age":4 } """)
simple.Age
simple.Name
The example was taken from here.