0

I am working on project where I need to call Web API which on success send json data along with other data. Now i have JSON schema as per their documentation so I want to parse data as per Schema mentioned so that I get everything in c# .

I know I can create a class manually then parse using Newtonsoft etc.. but Is there any way I can create class from JSON schema and parse output based upon that.

I have tried online tool to convert JSON to c# but as my schema contains property of each filed like whither required or datatype etc.. So not getting exact result even after parsring..

Json schema is as below

{
    "description": "Rightmove Realtime Datafeed Json Schema for GetBranchPerformance response",
    "type": "object",
    "properties": {
        "request_id": {
            "type": "string",
            "required": true,
            "description": "The unique ID of the request which this response is associated with"
        },
        "message": {
            "type": "string",
            "required": true,
            "description": "The message content for the response"
        },
        "success": {
            "type": "boolean",
            "required": true,
            "description": "Indicates whether or not the request was successful"
        },
        "request_timestamp": {
            "type": "string",
            "required": true,
            "description": "The time at which the request was received in the format: dd-MM-yyyy HH:mm:ss"
        },
        "response_timestamp": {
            "type": "string",
            "required": true,
            "description": "The time at which the response was sent in the format: dd-MM-yyyy HH:mm:ss"
        },
        "replication_lag": {
            "type": ["integer", "null"],
            "required": false,
            "description": "The current lag time for replicating between the three Rightmove data centres in minutes"
        },
        "export_date": {
            "type": ["string", "null"],
            "required": false,
            "description": "The date for the export period in the format: dd-MM-yyyy"
        },
        "branch": {
            "type": ["object","null"],
            "required": false,
            "description": "Information about the branch for which the metrics are being generated",
            "properties": {
                "branch_id": {
                    "type": "integer",
                    "id": "branch_id",
                    "required": true,
                    "description": "Unique Rightmove ID for the branch for which the performance metrics are being generated"
                }
            },
            "additionalProperties": false
        },
        "performance_data": {
            "type": ["object","null"],
            "required": false,
            "description": "Branch performance data, for the selected export date",
            "properties": {
                "email_leads": {
                    "type": "integer",
                    "required": true,
                    "description": "The total number of email leads received for a given branch, on the specified day"
                },
                "phone_leads": {
                    "type": "integer",
                    "required": true,
                    "description": "The total number of phone leads received for a given branch, on the specified day"
                },
                "property_data": {
                    "type": [
                        "array",
                        "null"
                    ],
                    "id":"property_data",
                    "required": false,
                    "description": "Details about performance by property on Rightmove",
                    "items": {
                        "type": "object",
                        "id": "each_property_data",
                        "required": true,
                        "properties": {
                            "agent_ref":{
                                "type":"string",
                                "required":true,
                                "description":"The agent's unique reference for the property"
                            },
                            "display_address": {
                                "type": "string",
                                "required": true,
                                "description": "The display address of the property on Rightmove"
                            },

                            "price": {
                                "type": "integer",
                                "required": true,
                                "description": "The current listed price for the property on Rightmove"
                            },
                            "channel":{
                                "type":["integer","null"],
                                "id":"channel",
                                "required":false,
                                "enum":[1, 2, null],
                                "description":"For dual branches it specifies the channel of the property: 1 Sales 2 Lettings"

                            },
                            "rightmove_id":{
                                "type":"integer",
                                "required":true,
                                "description":"Rightmove's unique reference for the property"
                            },
                            "rightmove_url":{
                                "type":"string",
                                "required":true,
                                "description":"The Rightmove URL for the property"
                            },
                            "featured_property":{
                                "type":"boolean",
                                "required":true,
                                "description":"Y/N - was the property a featured property on this date?"
                            },
                            "premium_listing":{
                                "type":"boolean",
                                "required":true,
                                "description":"Y/N - was the property a premium listing on this date?"
                            },
                            "summary_views": {
                                "type": ["object","null"],
                                "id": "summary_views",
                                "required": false,
                                "description": "Information on a property's summary views on Rightmove on the date specified",
                                "properties": {
                                    "total_summary_views": {
                                        "type":"integer",
                                        "required":true,
                                        "description":"The total number of times the property has appeared in a summary view on the requested date"
                                    },
                                    "desktop_summary_views": {
                                        "type":"integer",
                                        "required":true,
                                        "description":"The total number of times the property has appeared in a summary view on the requested date, when viewed from a desktop PC"
                                    },
                                    "mobile_summary_views": {
                                        "type":"integer",
                                        "required":true,
                                        "description":"The total number of times the property has appeared in a summary view on the requested date, when viewed from a mobile device"
                                    }
                                }
                            },
                            "detail_views": {
                                "type": ["object","null"],
                                "id": "detail_views",
                                "required": false,
                                "description": "Information on a property's detail views on Rightmove on the date specified",
                                "properties": {
                                    "total_detail_views": {
                                        "type":"integer",
                                        "required":true,
                                        "description":"The total number of detail views of the property on the requested date"
                                    },
                                    "desktop_detail_views": {
                                        "type":"integer",
                                        "required":true,
                                        "description":"The total number of detail views of the property on the requested date, when viewed from a desktop PC"
                                    },
                                    "mobile_detail_views": {
                                        "type":"integer",
                                        "required":true,
                                        "description":"The total number of detail views of the property on the requested date, when viewed from a mobile device"
                                    }
                                }
                            }
                        },
                        "additionalProperties": false
                    }
                }
            },
            "additionalProperties": false
        },

        "errors": {
            "type": [
                "array",
                "null"
            ],
            "required": false,
            "description": "The errors causing the request to fail",
            "minItems": 0,
            "items": {
                "type": [
                    "object",
                    "null"
                ],
                "required": false,
                "properties": {
                    "error_code": {
                        "type": "string",
                        "id": "error_code",
                        "required": true,
                        "description": "The unique Rightmove code for the error causing the request to fail"
                    },
                    "error_description":{
                        "type":"string",
                        "id":"error_description",
                        "required":true,
                        "description": "The full description of the error associated with the error code which has been generated"
                    },
                    "error_value":{
                        "type":["string", "null"],
                        "id":"error_value",
                        "required":false,
                        "description": "The value that caused this error"
                    }
                },
                "additionalProperties": false
            },
            "additionalProperties": false
        },
        "warnings": {
            "type": [
                "array",
                "null"
            ],
            "required": false,
            "description": "The warning generated by the request",
            "minItems": 0,
            "items": {
                "type": [
                    "object",
                    "null"
                ],
                "required": false,
                "properties": {
                    "warning_code": {
                        "type": "string",
                        "id": "warning_code",
                        "required": true,
                        "description": "The unique Rightmove warning code generated due to failure to pass all of the business rules"
                    },
                    "warning_description":{
                        "type":"string",
                        "id":"warning_description",
                        "required":true,
                        "description": "The full description of the warning associated with the warning code which has been generated"
                    },
                    "warning_value":{
                        "type":["string", "null"],
                        "id":"warning_value",
                        "required":false,
                        "description": "The value that caused this warning"
                    }
                },
                "additionalProperties": false
            },
            "additionalProperties": false
        }
    },
    "additionalProperties": false

}
Mahajan344
  • 2,492
  • 6
  • 39
  • 90
  • 1
    Use a web tool then tweak it as needed, no web tool will be perfect, what is stopping you from tweaking it's output? – Scott Chamberlain Feb 20 '17 at 16:53
  • If I use web tool that create class for each property which is not correct – Mahajan344 Feb 20 '17 at 16:54
  • You WILL need a class for each property registered as "object". Each object needs his own class. – Alberto Chiesa Feb 20 '17 at 16:58
  • Is this a duplicate? [Generate C# classes from JSON Schema](https://stackoverflow.com/questions/6358745/generate-c-sharp-classes-from-json-schema). – dbc Feb 20 '17 at 16:59
  • 1
    @dbc possibly, yes, it is a duplicate, and probably the question could directly point to that similar question. But this has a slightly different case: the OP is asking how to generate a single class from his schema. My point is he can't, but, other than that, he knows hot to generate is classes. Or this is what I'm currently understanding about this question. – Alberto Chiesa Feb 20 '17 at 17:02
  • Possible duplicate of [Generate C# classes from JSON Schema](http://stackoverflow.com/questions/6358745/generate-c-sharp-classes-from-json-schema) – Filip Cordas Feb 20 '17 at 17:15

0 Answers0