Schema.NET
Schema.NET copied to clipboard
If a json property starts with a capital letter, it is not included in the deserialized object
Describe the bug
For example, if the price on the offer is "Price", it will not be picked up.
Steps to reproduce
This unit test reproduces the issue:
[Test]
public void GetSchemaOrgOffers_GetOfferInProduct_GetPrice()
{
// Arrange
var pageContent = File.ReadAllText("C:/SchemaOrgTestPages/SchemaNetProductExample.json");
// Act
var product = SchemaSerializer.DeserializeObject<Product>(pageContent);
// Assert
Assert.IsTrue(product.Offers.Value2.Any(o => o.Price.HasValue1 || o.Price.HasValue2));
}
The contents of the SchemaNetProductExample file is:
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "Cucumber Mint Lip Balm",
"title": "Cucumber Mint Lip Balm",
"image": "https://www.burtsbees.com/dw/image/v2/AAPA_PRD/on/demandware.static/-/Sites-burtsbees-master-catalog/default/dw19603097/images/large/NI-44070_BBd_LIP_CB_4Pk_CucumberMint_Frnt_13-07-18-1300.jpg?sw=380&sh=380&sm=fit",
"description": "",
"brand": "Burt's Bees",
"sku": "792850905337",
"gtin": "792850900936",
"size": "4 Pack",
"color": "",
"offers": {
"@type": "Offer",
"url": "https://www.burtsbees.com/product/cucumber-mint-lip-balm/VM-792850900936.html",
"priceCurrency": "USD",
"Price": "11.99",
"availability": "http://schema.org/OutOfStock",
"itemCondition": "http://schema.org/NewCondition"
}
}
It works fine when the price is lower case and Assert.IsTrue passes. However when price starts with a captial P, the Assert.IsTrue fails as both HasValue1 and HasValue2 are false on the offer.
Expected behaviour
I think it should pick up the price irrelevant of the case, as the following website says it is valid schema.org: https://validator.schema.org/
Schema objects
https://schema.org/Offer
This one I'm more on the fence about - on one hand, you're right, the validator says it is fine. On the other, should we be potentially looking at more broad case insensitive parsing? I mean, while your example is the first letter, maybe we should be every letter of a property. Do we then look at enum values too and parse them case insensitively?
Schema.org doesn't specify any case sensitivity requirements that I could find so maybe the answer is we shouldn't be case sensitive either.
@RehanSaeed - I'm curious what you think when you're available to look at this.
We should make what we accept more open and accept case insensitive JSON as you suggest. We'd happily accept a PR to that effect.