Jamie Dixon
Jamie Dixon

Reputation: 4292

Json Type Provider: Parsing Valid Json Fails

I have the following code block in my REPL

#r "../packages/FSharp.Data.2.2.1/lib/net40/FSharp.Data.dll"

open FSharp.Data

[<Literal>]
let uri = "http://www.google.com/finance/option_chain?q=AAPL&output=json"

type OptionChain = JsonProvider<uri>

When I run it, FSI is returning

Error 1 The type provider 'ProviderImplementation.JsonProvider' reported an error: Cannot read sample JSON from 'http://www.google.com/finance/option_chain?q=AAPL&output=json': Invalid JSON starting at character 1, snippet =
---- {expiry:{y:2
----- json =
------ {expiry:{y:2015,m:5,d:8},expirations: [{y:2015,m:5,d:8},{y:2015,m:5,d:15},

This json is valid according to two other sites. Is it a bug in the TP?

Upvotes: 1

Views: 384

Answers (1)

Ming-Tang
Ming-Tang

Reputation: 17651

The output isn't valid JSON because some keys are not quoted.

{expiry:{y:2015,m:5,d:8},expirations:[{y:2015,m:5,d:8},{y:2015,m:5,d:15},{y:2015,m:5,d:22},{y:2015,m:5,d:29},{y:2015,m:6,d:5},{y:2015,m:6,d:12},{y:2015,m:6,d:19},{y:2015,m:6,d:26},{y:2015,m:7,d:17},{y:2015,m:8,d:21},{y:2015,m:10,d:16},{y:2016,m:1,d:15},{y:2017,m:1,d:20}],
 puts:[{cid:"43623726334021",s:"AAPL150508P00085000",e:"OPRA",p:"-",c:"-",b:"-",a:"-",oi:"-",vol:"-",strike:"85.00",expiry:"May 8, 2015"},
 ...

Upvotes: 2

Related Questions