Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return JSON in camelCase instead of PascalCase #213

Closed
yamin8000 opened this issue Dec 20, 2021 · 4 comments
Closed

Return JSON in camelCase instead of PascalCase #213

yamin8000 opened this issue Dec 20, 2021 · 4 comments

Comments

@yamin8000
Copy link

How can I config either GrandNode or OData to return JSON in camelCase instead of the current default which is returning in PascalCase?

sample:

{
    "Name": "Xiaomi",
    "SeName": "xiaomi",
    "Description": null,
    "BottomDescription": null,
    "BrandLayoutId": "61b57b85892acc894cd7efb9",
    "MetaKeywords": null,
    "MetaDescription": null,
    "MetaTitle": null,
    "PictureId": "61b57b85892acc894cd7f020",
    "PageSize": 6,
    "AllowCustomersToSelectPageSize": true,
    "PageSizeOptions": "6, 3, 9",
    "ShowOnHomePage": false,
    "IncludeInMenu": false,
    "Icon": null,
    "Published": true,
    "ExternalId": null,
    "DisplayOrder": 1,
    "Id": "61b57b85892acc894cd7f01f"
  }
@KrzysztofPajak
Copy link
Member

@yamin8000
I think it doesn't matter if you send a field i.e. Name with upper case or lower case.

@yamin8000
Copy link
Author

@yamin8000 I think it doesn't matter if you send a field i.e. Name with upper case or lower case.

Thank you for your swift response.
Yeah for sending data to the server maybe that doesn't matter but it would be great if API consumer (Client) could receive JSON in the desired format (one way of that is using HTTP headers), many JSON parsers are very strict when it comes to field name cases and consider Name or name two completely different fields.

@KrzysztofPajak
Copy link
Member

@yamin8000
It looks like it's possible, find the file ODataStartup.cs => Method GetEdmModel:
private IEdmModel GetEdmModel(ApiConfig apiConfig)
{
var builder = new ODataConventionModelBuilder {
Namespace = Configurations.ODataModelBuilderNamespace,
};
//add this line
builder.EnableLowerCamelCase();
RegisterDependencies(builder, apiConfig);
return builder.GetEdmModel();
}

@yamin8000
Copy link
Author

@yamin8000 It looks like it's possible, find the file ODataStartup.cs => Method GetEdmModel: private IEdmModel GetEdmModel(ApiConfig apiConfig) { var builder = new ODataConventionModelBuilder { Namespace = Configurations.ODataModelBuilderNamespace, }; //add this line builder.EnableLowerCamelCase(); RegisterDependencies(builder, apiConfig); return builder.GetEdmModel(); }

Thank you. This actually helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants