Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access FSharp.Data.JsonExtensions?

Tags:

f#

f#-data

Sorry if this question is a bit unclear. It was the best I could do in my state of confusion about packages in F# 4.0.

The book Expert F# 4.0 by Don Syme, Adam Granicz, and Antonio Cisternino contains code that processes JSON data. The code starts with

open FSharp.Data
open FSharp.Data.JsonExtensions

I have FSharp.Data installed in Visual Studio. Still, the word "JsonExtensions" gets red squiggles under it and the rest of the code does not compile.

Going to Add References in the Solution Explorer I did not find a package FSharp.Data.JsonExtensions. I also looked under NuGet and found no package FSharp.Data.JsonExtensions. There is documentation for JsonExtensions
which suggests it is a module. However, using the dot in Visual Studio it does not appear under FSharp.Data. (There is only one entry: Unit Systems)

How can I make the code in this module available so I can run the code in the book?

like image 359
Soldalma Avatar asked Oct 18 '22 16:10

Soldalma


1 Answers

This happens because actually you don't have FSharp.Data installed (So Foggy is right above). There is an FSharp.Data namespace but you need to nuget the package to be able to use it. So go to Tools | Nuget Package Manager | Manage Nuget Packages for Solution and download the latest and greatest FSharp.Data. This will automatically add it to your references file in VS:

Nuget the package

See:

enter image description here

Now you can use it:

enter image description here

If you are using it from an .fsx script make sure to reference it with #r

#r @"..\packages\FSharp.Data.2.3.2\lib\net40\FSharp.Data.dll"

In that case you can just right-click on the References (after nugetting) and VS will generate you the path:

enter image description here

If you don't see Send to F# Interactive I strongly suggest you install the Visual F# Power Tools.

You can explore other ways of accessing/serializing JSON files: there is the JSON type provider, Newtonsoft JSON, FSharplu, Chiron, and FSPickler.

like image 200
s952163 Avatar answered Oct 21 '22 01:10

s952163