Open jruizaranguren opened 10 years ago
Sounds great! Send in the PR :)
PR?
Sorry, Pull Request
This would be a nice feature to add - and it is actually not that hard to implement!
The key thing is to parse the JSON schema and, based on the schema, generate value of the InferedType
discriminated union (you can see It here), which is our internal representation of a type. Once we have that, the rest of the type provider can generate a nice .NET type from the internal representation (including things like options).
Aside from that, you'd have to add static parameter (say Schema
) to the list of parameters, and change the code that reads the sample to instead look at the schema (and produce InferedType
)
Thanks Thomas. I will have a look at the weekend and see if I can make a first draft. Could you give an estimation of the effort needed for this feature? (I will multiply for 10 to get my own estimate anyway :-)
It is difficult to give any estimates, but I believe that this is one of the easier (but fairly significant) features to implement! It is mainly a matter of parsing JSON schema (possibly using our JsonValue
that is already in F# Data) and extracting the information from there into our internal structures. But I have learned enough about software engineering to avoid giving any estimates :-).
Also, when you start working on this in your repository, feel free to send a pull-request with the work in progress, so that we can give you more feedback (and answer any questions you may have).
Jet.com has released sources for a related project: https://github.com/jet/JsonSchemaProvider
@blumu, it depends on Json.Net and it just conforms to JSON-Schema v3 (deprecated). Newtonsoft released a JsonSchema library, but it has license restrictions.
Was work ever started on this? Are you still looking for someone to pick it up?
I wonder too
@tpetricek can we get this going again? Is it technical seen still relevant?
@realvictorprm I do not know how widely is JSON Schema adopted, but aside from that, this still sounds interesting and relevant, so if anyone wants to have a go, I'm all for it :)
Good, need this for glTF which specification is in schema json. Can you point me a bit?
@tpetricek I have some questions which need to be answered so I can start developing a new up to date json schema type provider:
@tpetricek feel free to assign this to me.
Tracking PR is #1069
I'm confused as to the original posters intent for a pull request. Do you wish to allow json schemas to become a JsonProvider type for multiple json files, which implement the same schema? Currently I don't think this is possible since JsonProvider still includes json-schema specific keywords, such as Properties
.
The best workaround I use is to use any one of the schema implementing files as the JsonProvider's source.
@doublecouponday that's right. I meant a type provider generating types based off a JSON schema file. The suggested workaround is not meeting the requirement, in particular a single sample JSON cannot always represent all the possible JSON files accepted by a given schema.
This would be so great to have! I have a list of json files that all follow the same schema. I would be great to load JsonProvider with a schema and then parse individual files! Without it, i have to have a provider for each separate file, which is not scalable
This would be a nice feature to add - and it is actually not that hard to implement!
The key thing is to parse the JSON schema and, based on the schema, generate value of the
InferedType
discriminated union (you can see It here), which is our internal representation of a type. Once we have that, the rest of the type provider can generate a nice .NET type from the internal representation (including things like options).Aside from that, you'd have to add static parameter (say
Schema
) to the list of parameters, and change the code that reads the sample to instead look at the schema (and produceInferedType
)
Say I wanted to give I wanted to pick this up and start my own attempt a pull request for this feature. Any advice from @tpetricek or @dsyme as to where to start? I was going to look at how the XML Type Provider uses XSDs to generate types.
Jet.com has released sources for a related project: https://github.com/jet/JsonSchemaProvider
Does anybody have a copy of this repo? It no longer exists.
There is a newer one https://github.com/florenzen/JsonSchemaProvider It works but it is not production-ready. The author agrees to reuse that code to FSharp.Data. I tried improving it and migrating it from NJsonSchema to JsonSchema.Net here
Json-Schema could provide us with a principled and standardized way to understand json data. Although it has not got much traction yet is a powerfull and complete standard with a couple of decent implementations.
It migth simplify type inference and reduce ambiguity. It also allows for shareable lightweight data specifications.
A brief brainstorming of json-schema keywords that could be used to leverage F# characteristics:
We would also have a standard way to:
I'm willing to contribute to this approach, I have worked with json-schema a couple of months.