JSON schema to VB.Net results in non-working code for collections

Never having worked with Newtonsoft before, I read many threads here and found that producing the model object should be easy: use one of the many online tools to convert the schema to VB.net (or C# and convert). My attempts to do so have all failed, that also includes using a pure C# conversion. The issue has to do with collections (I think) or maybe just the schema file itself.

The original schema is 3500 lines, here’s a snippet (it’s NDA so I don’t know how much I can post). This is right near the top, it’s part of the definition of the root object:

"properties": {
    "Properties": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "$ref": "#/definitions/Property"
      }
    }

And then later in the code is a definition of the Property object, which is basically just a bunch of strings:

"Property": {
  "type": "object",
  "required": [
    "Name",
    "Location",
    "ID",
    "ObjectType"
  ],
  "properties": {
    "Messages": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "$ref": "#/definitions/Message"
      }
    },
    "Name": {
      "$ref": "#/definitions/$basicType/definitions/requiredString"
    },
    "Location": {
      "$ref": "#/definitions/$basicType/definitions/requiredString"
    },
    ... more of same...

I read this as the root JSON has a structure called “Properties” that is an array of Property objects, which has a Messages collection (which are just strings) and then a bunch of fields. Looking at a sample file of the output JSON, I see a single object in the collection (as expected):

"Properties":[{"ID":"33...

First up, I tried jsonutils.com, as it has direct JSON->VB. That produced this:

Public Class Items
    Public Property $ref As String
End Class

Public Class Properties
    Public Property type As String
    Public Property minItems As Integer
    Public Property uniqueItems As Boolean
    Public Property items As Items
End Class

Public Class Properties
    Public Property Version As Version
    Public Property Messages As Messages
    Public Property Properties As Properties
End Class

....

Public Class Property
    Public Property type As String
    Public Property required As String()
    Public Property properties As Properties
End Class

Among the many issues, it defined two classes called Properties. Moreover, the list, items, is not a collection of Property objects but a reference to a new class called Items which is a ref to a Properties, which doesn’t refer to Property objects. This is not the only instance of an items collection in the schema, and it converted them all to Items despite them pointing to different underlying objects.

Next up, I tried the alternative suggestion of making a C# version using JSON2Csharp (now THAT’s funny, it autocorrected to “shart”!), and then converting that. Realizing the two-step process was unlikely to work out of the box, I instead made a new C# project and put the results in there. This too gave me many lines like…

public Items items { get; set; }

But this time it didn’t bother to make an Items class at all, so these are just errors.

OK, questions:

  1. does anyone know of a tool that properly handles this sort of JSON schema? I assume it’s the $ or # that’s confusing it? I saw many references to various downloadable tools, but I can no longer find any of them online.

  2. failing that, I suspect I simply have to convert the various items references to a collection type, but I’m not familiar with NS, so are these simply List(Of Property) or does it expect some other type during deserialization?

13

Google, having failed to turn up anything useful, did point me to the JSON Schema discord. A post there turns up the answer to this thread:

corvus-dotnet/Corvus.JsonSchema

Personally I would have preferred to use an online tool, but having installed this tool it immediately produced a working object model and I’ll definitely recommend it to everyone.

For those of you wondering, the advantage to using the schema file (aside from that being all I had) is that it contains much more metadata that is absolutely useful… things like which fields are required and which are optional, the types of the objects in an array, etc. These flesh out the object model much more than using an actual JSON file.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật