Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsonProvider "This is not a constant expression or valid custom attribute value"

Given the code:

#if INTERACTIVE
#r "bin\Debug\FSharp.Data.dll"

#endif

open System
open FSharp.Data
open FSharp.Data.Json

let testJson = """{ "workingDir":"hello", "exportDir":"hi there", "items":[{ "source":"", "dest":"", "args": {"name":"that"} }] }"""

//here is where i get the error
let Schema = JsonProvider<testJson>

The last line keeps giving me the error "This is not a constant expression or valid custom attribute value"-- what does that mean? How can i get it to read this JSON?

like image 990
Micah Avatar asked Jul 21 '13 11:07

Micah


1 Answers

The string has to be marked as a constant. To do that, use the [<Literal>] attribute. Also, the type provider creates a type, not a value, so you need to use type instead of let:

open FSharp.Data

[<Literal>]
let testJson = """{ "workingDir":"hello", "exportDir":"hi there", "items":[{ "source":"", "dest":"", "args": {"name":"that"} }] }"""

type Schema = JsonProvider<testJson>
like image 198
svick Avatar answered Oct 29 '22 00:10

svick