hilalhakla / Json2CSharpCodeGenerator

Microsoft Reciprocal License
308 stars 86 forks source link

Json2CSharp Keywords are not escaped. #10

Closed michaelcheers closed 4 years ago

michaelcheers commented 4 years ago

You need to escape keyword names such as return. Example JSON:

{ "response": { "value": { "search_params": { "to_type": "airport", "flyFrom_type": "airport" }, "time": 1, "connections": [], "currency": "pln", "currency_rate": 0.2348, "data": { "airlines": [ "W6", "FR" ], "baglimit": { "hand_height": 40, "hand_length": 55, "hand_weight": 7, "hand_width": 23, "hold_height": 52, "hold_length": 78, "hold_weight": 20, "hold_width": 28, "hold_dimensions_sum": 158 }, "bags_price": {}, "booking_token": "oKWrjE3p79Fphzv+baF3C2h1PDgCet9WaEXSzPuPgCEbnZfp1jYeu4WPBYkWhnvFVdMUHtSDW6qgykuuve1Fglx/Cp7ojKGgP1wN57eDDm7174lwXFwCaExwY1oviADeYzWzkvgFnSYx5w19mnX0t3KunnedJScRvA426om/JqXmCfbfEnVyryB+6ywjr8CmwBhAaTGz8UFxe2F+S2Ck6XhTPyoaf8VI4gBOnoVY1rlXVE/Xi+9bnpqQN+jP8i74zmLVb4LiWhMreQqaG1acc0xIEdZQxq1qllX0t9JSsYyZ8kS41KheurCLH/u2mpJgowJnySLQ/w5a0J7yKb7dBF+/6CVD52a+FH6PibsRXJWNQso336gGlqfjIQ72f8Oi2Ep7IXzuKPOvC2W/Ucp5Le+n0kz6VckLLrol1IkFwCAkP0Pyf5v6FrsWEYF53la5Ig3dLDPy32Yhpu9L1TqImtfryq3mFr53Fh6Z/hZoaJH7yfd2h8aqj92snLfCkvl72VAfJITkdE8vMNGz5quCYw60mgUdXvBMzaNeSPgtWMKRM+kzzTb2YJwmBhjS8B8Qa8j/zixcnMEiO4VdksgZq2dcFpm7fjx670ml0y87G4+ebECvzDaP8oClNJ2WmFtl3R8/EQ+2+LaUKrktN/OWDJT92sfS1K7LP1OTC/1uQrHG4vSqo0A+SofRTw2UP/08kxoJoc6IkrsdmVPQlPRIPi/r9cPsWaRe1JsoBYCa0tz2FWWXr1pLX3RQjrNUq2Vo8Ns6/FItzkr4CNhtHOTin6qITvyTqio610v5ovrhS4lL13yIYfHu0s3n0d/Gp/DWryGOZsIC5v+D9S8P/s5hCP9m51gizRSNjpQn/LpFin23pztXPRR6gvHVXZKRhUOAdyyis5gPHL+9A7n7THciyKVs0bM3XhQG3EpUWhCYUpjVRPF69+2RXENVCOF3Ys9SfBjsv3vcsJTMNQs2Fh+Sk1hHnY9WkgWs3EK8lN0mx2NOcdKU6nAxg4np4QtyF/I5SU33wMBxXdJ3BpltM33TGUG9xpeN0DPLP0S1oXfjIdGfBrLPJqpq7S2QC44BekgXdYYje92wUW7aJYAJhaJi2e93Q5JGf3V6caaxWTa8xsQ=", "cityFrom": "Prague", "cityTo": "Frankfurt", "conversion": { "EUR": 104 }, "countryFrom": { "code": "CZ", "name": "Czechia" }, "countryTo": { "code": "DE", "name": "Germany" }, "deep_link": "https://www.kiwi.com/deep?from=PRG&to=FRA&departure=04-12-2018&return=06-12-2018&flightsId=4210030485405823_0%7C3971436194349625_0%7C3971436206433809_0%7C3908763979435451_0%7C3956043040686669_0&price=104&passengers=1&affilid=kayak_en&lang=en&currency=EUR&booking_token=oKWrjE3p79Fphzv+baF3C2h1PDgCet9WaEXSzPuPgCEbnZfp1jYeu4WPBYkWhnvFVdMUHtSDW6qgykuuve1Fglx/Cp7ojKGgP1wN57eDDm7174lwXFwCaExwY1oviADeYzWzkvgFnSYx5w19mnX0t3KunnedJScRvA426om/JqXmCfbfEnVyryB+6ywjr8CmwBhAaTGz8UFxe2F+S2Ck6XhTPyoaf8VI4gBOnoVY1rlXVE/Xi+9bnpqQN+jP8i74zmLVb4LiWhMreQqaG1acc0xIEdZQxq1qllX0t9JSsYyZ8kS41KheurCLH/u2mpJgowJnySLQ/w5a0J7yKb7dBF+/6CVD52a+FH6PibsRXJWNQso336gGlqfjIQ72f8Oi2Ep7IXzuKPOvC2W/Ucp5Le+n0kz6VckLLrol1IkFwCAkP0Pyf5v6FrsWEYF53la5Ig3dLDPy32Yhpu9L1TqImtfryq3mFr53Fh6Z/hZoaJH7yfd2h8aqj92snLfCkvl72VAfJITkdE8vMNGz5quCYw60mgUdXvBMzaNeSPgtWMKRM+kzzTb2YJwmBhjS8B8Qa8j/zixcnMEiO4VdksgZq2dcFpm7fjx670ml0y87G4+ebECvzDaP8oClNJ2WmFtl3R8/EQ+2+LaUKrktN/OWDJT92sfS1K7LP1OTC/1uQrHG4vSqo0A+SofRTw2UP/08kxoJoc6IkrsdmVPQlPRIPi/r9cPsWaRe1JsoBYCa0tz2FWWXr1pLX3RQjrNUq2Vo8Ns6/FItzkr4CNhtHOTin6qITvyTqio610v5ovrhS4lL13yIYfHu0s3n0d/Gp/DWryGOZsIC5v+D9S8P/s5hCP9m51gizRSNjpQn/LpFin23pztXPRR6gvHVXZKRhUOAdyyis5gPHL+9A7n7THciyKVs0bM3XhQG3EpUWhCYUpjVRPF69+2RXENVCOF3Ys9SfBjsv3vcsJTMNQs2Fh+Sk1hHnY9WkgWs3EK8lN0mx2NOcdKU6nAxg4np4QtyF/I5SU33wMBxXdJ3BpltM33TGUG9xpeN0DPLP0S1oXfjIdGfBrLPJqpq7S2QC44BekgXdYYje92wUW7aJYAJhaJi2e93Q5JGf3V6caaxWTa8xsQ=", "distance": 406.5, "duration": { "departure": 15600, "return": 34800, "total": 50400 }, "facilitated_booking_available": false, "flyFrom": "PRG", "flyTo": "FRA", "has_airport_change": false, "id": "4210030485405823_0|3971436194349625_0|3971436206433809_0|3908763979435451_0|3956043040686669_0", "local_arrival": "2018-12-04T16:35:00.000Z", "local_departure": "2018-12-04T12:15:00.000Z", "nightsInDest": 2, "pnr_count": 5, "price": 104, "quality": 239.99966, "rank": 0.0092, "route": [ { "airline": "FR", "bags_recheck_required": false, "cityFrom": "Prague", "cityTo": "Budapest", "combination_id": "4210030485405823", "equipment": null, "fare_basis": "NZ1299DC", "fare_classes": "N", "fare_family": "", "flight_no": 4092, "flyFrom": "PRG", "flyTo": "BUD", "guarantee": false, "id": "4210030485405823_0", "last_seen": "2018-11-08T15:30:07.000Z", "local_arrival": "2018-12-04T13:25:00.000Z", "local_departure": "2018-12-04T12:15:00.000Z", "operating_carrier": null, "refresh_timestamp": "2018-11-08T15:30:07.000Z", "return": 0, "utc_arrival": "2018-12-04T12:25:00.000Z", "utc_departure": "2018-12-04T11:15:00.000Z", "vehicle_type": "aircraft" }, { "airline": "W6", "bags_recheck_required": false, "cityFrom": "Budapest", "cityTo": "Frankfurt", "combination_id": "3971436194349625", "equipment": null, "fare_basis": "PRREG", "fare_classes": "P", "fare_family": "", "flight_no": 2311, "flyFrom": "BUD", "flyTo": "FRA", "guarantee": true, "id": "3971436194349625_0", "last_seen": "2018-11-08T15:52:47.000Z", "local_arrival": "2018-12-04T16:35:00.000Z", "local_departure": "2018-12-04T14:50:00.000Z", "operating_carrier": null, "refresh_timestamp": "2018-11-08T15:52:47.000Z", "return": 0, "utc_arrival": "2018-12-04T15:35:00.000Z", "utc_departure": "2018-12-04T13:50:00.000Z", "vehicle_type": "aircraft" }, { "airline": "FR", "bags_recheck_required": false, "cityFrom": "Frankfurt", "cityTo": "Venice", "combination_id": "3971436206433809", "equipment": null, "fare_basis": "NZ999DC", "fare_classes": "N", "fare_family": "", "flight_no": 2416, "flyFrom": "FRA", "flyTo": "TSF", "guarantee": false, "id": "3971436206433809_0", "last_seen": "2018-11-08T15:43:23.000Z", "local_arrival": "2018-12-06T14:30:00.000Z", "local_departure": "2018-12-06T13:10:00.000Z", "operating_carrier": null, "refresh_timestamp": "2018-11-08T15:43:23.000Z", "return": 1, "utc_arrival": "2018-12-06T13:30:00.000Z", "utc_departure": "2018-12-06T12:10:00.000Z", "vehicle_type": "aircraft" }, { "airline": "FR", "bags_recheck_required": false, "cityFrom": "Venice", "cityTo": "City of Brussels", "combination_id": "3908763979435451", "equipment": null, "fare_basis": "NZ999DC", "fare_classes": "N", "fare_family": "", "flight_no": 6056, "flyFrom": "TSF", "flyTo": "CRL", "guarantee": true, "id": "3908763979435451_0", "last_seen": "2018-11-08T15:06:39.000Z", "local_arrival": "2018-12-06T18:45:00.000Z", "local_departure": "2018-12-06T17:05:00.000Z", "operating_carrier": null, "refresh_timestamp": "2018-11-08T15:06:39.000Z", "return": 1, "utc_arrival": "2018-12-06T17:45:00.000Z", "utc_departure": "2018-12-06T16:05:00.000Z", "vehicle_type": "aircraft" }, { "airline": "FR", "bags_recheck_required": false, "cityFrom": "City of Brussels", "cityTo": "Prague", "combination_id": "3956043040686669", "equipment": null, "fare_basis": "NZ1299DC", "fare_classes": "N", "fare_family": "", "flight_no": 2121, "flyFrom": "CRL", "flyTo": "PRG", "guarantee": true, "id": "3956043040686669_0", "last_seen": "2018-11-08T15:54:24.000Z", "local_arrival": "2018-12-06T22:50:00.000Z", "local_departure": "2018-12-06T21:20:00.000Z", "operating_carrier": null, "refresh_timestamp": "2018-11-08T15:54:24.000Z", "return": 1, "utc_arrival": "2018-12-06T21:50:00.000Z", "utc_departure": "2018-12-06T20:20:00.000Z", "vehicle_type": "aircraft" } ], "routes": [ "- PRG\n- FRA", "- FRA\n- PRG" ], "transfers": [], "type_flights": [ "lcc-FR", "lcc-W6" ], "utc_arrival": "2018-12-04T15:35:00.000Z", "utc_departure": "2018-12-04T11:15:00.000Z" } } } }

The return comes up as return and then it messes up the file. It should be @return.

List of reserved words (for your convenience):

abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual void volatile while

They should be replaced each reserved word with @reservedword.

michaelcheers commented 4 years ago

Also, it seems that if the keys on the json are numbers, they aren't escaped. You could escape those with an underscore. I'm not sure if you would have to also add an attribute.

hilalhakla commented 4 years ago

Yes this issue was raised before i havn't got the time to fix it yet, should be easy but i'm super busy these two weeks, i will make the project open source for contribution and add these two cases as unit tests, this will take some time in order to properly set up documenationts, anyway thanks for letting me know !

michaelcheers commented 4 years ago

No worries. It is pretty easy to fix manually. Your tool is awesome by the way. It saves me so much time.

On Thu, Aug 6, 2020 at 1:27 PM Json2CSharp notifications@github.com wrote:

Yes this issue was raised before i havn't got the time to fix it yet, should be easy but i'm super busy these two weeks, i will make the project open source for contribution and add these two cases as unit tests, this will take some time in order to properly set up documenationts, anyway thanks for letting me know !

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Json2CSharp/Json2CSharp/issues/10#issuecomment-670175264, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACNW74QEG2CYTDLT6W22YKLR7MG2LANCNFSM4PW3IRHA .

hilalhakla commented 4 years ago

I'm glad you like it many Thanks !

tyeth commented 4 years ago

Just to add, thank you, this has saved me hours of messing about, maybe I'll take a look

tyeth commented 4 years ago

Had a first stab, seems okay but not thought about class definitions, only class members (fields/properties). Added failing test then worked from there. #14 Have a look @Json2CSharp and let me know if there are changes I should make.

Also forgot to mention that the other site that regularly saves my life is https://nimbletext.com/Live