0

We have a json object provided by vendor with naming conventions suitable only for vendor system. We would like to rename all the json attributes names matching our company's naming standards. I showed a very small XML file but in reality we have a huge XML with many elements. The transformed json object will eventually be persisted in our datastore.Any inputs in handling efficient way?

Json Example Provided by Vendor

{
  "Events": [
  {
     "TestOn": {
        "TestCode": "32",
        "TestSubCode": "11",
        "TestStatus": "4",
     },
     "Timers": {
        "TestOpCode": "10",
        "TestMode": "4",
        "TestItemTime": "4",
     }
  }
  ],
  "Ticket": [
  {
    "Discount": {
        "OpCode": "3",
        "CluCode": "00001530020003",
        "DeptNo": "11",
     },
     "Promotion": {
        "OpCode": "96",
        "SubCode": "26",
        "F-Promotion": "1",
     }
  }

] }

Transformed Json Object

{
  "PxEvents": [
  {
     "PxTestOn": {
        "PxTestCode": "32",
        "PxTestSubCode": "11",
        "PxTestStatus": "4",
     },
     "PxTimers": {
        "PxTestOpCode": "10",
        "PxTestMode": "4",
        "PxTestItemTime": "4",
     }
  }
  ],
  "PxTicket": [
  {
    "PxDiscount": {
        "PxOpCode": "3",
        "PxCluCode": "00001530020003",
        "DeptNo": "11",
     },
     "PxPromotion": {
        "PxOpCode": "96",
        "PxSubCode": "26",
        "PxPromotion": "1",
     }
  }

] }

user7987134
  • 149
  • 1
  • 3
  • 12
  • Well, you can always [remap a Json property to a differently named c# property](https://stackoverflow.com/questions/8796618/how-can-i-change-property-names-when-serializing-with-json-net/8796648), but I guess what you're looking for is [reconstructing the json with a renamed property](https://stackoverflow.com/questions/11679804/json-net-rename-properties). – gunr2171 Oct 08 '20 at 03:05
  • 1
    I’m voting to close this question because your question with its _["no actual problem to be solved"](https://stackoverflow.com/help/dont-ask)_, kinda sounds like _code improvement_ and/or _review_ and if so may be off-topic for SO. It _may_ be better suited for another SE site but be sure to read the relevant FAQ; and/or re-wording your question as necessary before cross-posting. [ask]. Good luck! –  Oct 08 '20 at 03:07
  • Create two classes. One with `JsonProperty` set to the initial JSON. One with `JsonProperty` that are appaopriate for the final JSON. Write an automapper or explicit code to convert one class to the other. Deserialise into the former. Convert to the latter. Serialise into JSON from the latter. – mjwills Oct 08 '20 at 03:11

0 Answers0