This question already has answers here:
How can I parse a JSON string that would cause illegal C# identifiers?
(3 answers)
Closed 8 years ago.
I am attempting to parse JSON from a web service using Json.NET, the web service returns data in the following format:
{
"0": {
"ID": 193,
"Title": "Title 193",
"Description": "Description 193",
"Order": 5,
"Hyperlink": "http://someurl.com"
},
"1": {
"ID": 228,
"Title": "Title 228",
"Description": "Description 228",
"Order": 4,
"Hyperlink": "http://someurl.com"
},
"2": {
"ID": 234,
"Title": "Title 234",
"Description": "Description 234",
"Order": 3,
"Hyperlink": "http://someurl.com"
}
}
I used json2sharp to generate a class from the JSON:
public class __invalid_type__0
{
public int ID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int Order { get; set; }
public string Hyperlink { get; set; }
}
public class __invalid_type__1
{
public int ID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int Order { get; set; }
public string Hyperlink { get; set; }
}
public class __invalid_type__2
{
public int ID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int Order { get; set; }
public string Hyperlink { get; set; }
}
public class RootObject
{
public __invalid_type__0 __invalid_name__0 { get; set; }
public __invalid_type__1 __invalid_name__1 { get; set; }
public __invalid_type__2 __invalid_name__2 { get; set; }
}
I then cleaned up the class and was left with the following:
public class Articles
{
public int ID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int Order { get; set; }
public string Hyperlink { get; set; }
}
public class FeaturedArticles
{
public List<Articles> articles { get; set; }
}
When I attempt to load the data into my singleton for use in the app:
private void fetchFeaturedArticles()
{
var client = new RestClient (_featuredArticlesJsonUrl);
var request = new RestRequest (Method.GET);
var response = client.Execute (request);
_featuredArticles = JsonConvert.DeserializeObject<FeaturedArticles> (response.Content);
foreach (Articles a in _featuredArticles.Articles)
Console.WriteLine (a.Title);
}
I find that the Articles do not get deserialized.
I've verified that the JSON data is returned from the web service. I believe the issue exists in the structure of my JSON feed, where each item returned from the feed is given a name which equals the index the item is being returned as.
I am new to using Json.NET so I'm not sure how I should proceed; I cannot change the structure of the JSON feed but need to consume it's data. Anyone have any recommendations?
You don't need FeaturedArticles class, you can deserialize the JSON into a Dictionary<string, Articles> like this:
private void fetchFeaturedArticles()
{
var client = new RestClient (_featuredArticlesJsonUrl);
var request = new RestRequest (Method.GET);
var response = client.Execute (request);
Dictionary<string, Articles> _featuredArticles = JsonConvert.DeserializeObject<Dictionary<string, Articles>>(response.Content);
foreach (string key in _featuredArticles.Keys)
{
Console.WriteLine(_featuredArticles[key].Title);
}
}
Demo: https://dotnetfiddle.net/ZE1BMl
Related
I am calling a Solr Apache search url and it turns Json data format. However, when I parse the Json, I receive null data. My Json format is like below:
responseHeader:
status: 0
QTime: 1
params:
q: "mykeyword"
response:
numFound: 67
start: 0
docs:
0:
tstamp: "xxxxx.xxxx.xxxx"
digest: "xxxxxxxxxxxxxxx"
boost: 0.010186654
id: "https://myserer/faq.html"
title: "xxxx"
url: "xxxxxx"
_version_:"xxxxxx"
content: "xxxxxxxxxx"
1:
tstamp: "xxxx"
.....
so I created dataModel to map the json data format:
public class ResponseModel
{
public ResponseHeader responseheader { get; set; }
public Response_ responsedata { get; set; }
}
public class Response_
{
public int numFound { get; set; }
public int start { get; set; }
public Doc doc { get; set; }
}
public class Params
{
public string q { get; set; }
}
public class Page
{
public string tstamp { get; set; }
public string digest { get; set; }
public string boost { get; set; }
public string id { get; set; }
public string title { get; set; }
public string url { get; set; }
public string _version_ { get; set; }
public string content { get; set; }
}
public class Doc
{
public List<Page> pages { get; set; }
}
my code to retrieve json search results:
string baseURL = "http://myserver:8983/solr/nutch/select?q=" + keyword;
string responseBody = string.Empty;
keyword = Request.Form["txtSearchTerm"];
if (!string.IsNullOrEmpty(keyword))
{
responseBody = getJSONString(baseURL);
}
var myData = JsonConvert.DeserializeObject<ResponseModel>(responseBody);
var Response = myData.responsedata.doc; //The Response is null here
// ...
private static string getJSONString(string apiURL)
{
// it returns json string
}
Where is the problem? BTW, there are a lot of \n line break in the json data. Is that the problem and how to deal with it? Thanks
add json data sample below:
{
"responseHeader": {
"status": 0,
"QTime": 0,
"params": {
"q": "Intranet"
}
},
"response": {
"numFound": 19,
"start": 0,
"docs": [
{
"tstamp": "2020-05-20T01:23:56.427Z",
"digest": "d615d21052125d3023a6ea5a244a6be0",
"boost": 0.043801095,
"id": "https://myserver/services/index.html",
"title": "Office of Services",
"url": "https://myserver/services/index.html",
"content": "Office of Services\nWelcome to the xxxx Website\nAccessibility Navigation:\nSkip to the header\nSkip to the main content\nSkip to the footer\nIt appears that you are viewing this site with an outdated browser.\nUpdate your browser for the best viewing experience by downloading the latest version below:\nInternet Explorer\nGoogle Chrome\nFirefox\nSafari\nMenu\nSearch\nSearch\n ...\nTop\n",
"_version_": 1667170768636608512
},
{
"tstamp": "2020-05-20T01:23:56.426Z",
"digest": "16cc4c01acd01d15ddbc59b7d43b435f",
"boost": 0.045213405,
"id": "https://myserver/media/index.html",
"title": "Library Technical",
"url": "https://myserver/media/index.html",
"content": "Library Technical Services Website\nAccessibility Navigation:\nSkip to the header\nSkip to the main content\nSkip to the footer\nIt appears that you are viewing this site with an outdated browser.\nUpdate your browser for the best viewing experience by downloading the latest version below:\nInternet Explorer\nGoogle Chrome\nFirefox\nSafari\nMenu\nSearch\nSearch\n ... INTRANET\Top\n",
"_version_": 1667170768619831298
}
]
}
}
The problem is that you have an object in your json namely response and in your c# classes, you have created the property named responseData which won't map because they differ in the name, Either you would have to set the JsonProperty name to response or you should entirely change the name of your property to response. Besides, there is a web application that will correctly parse your json and will generate the C# classes for you relevantly. Here is the code that I have generated for you for the response you have shared:
public partial class WebRequestResult
{
[JsonProperty("responseHeader")]
public ResponseHeader ResponseHeader { get; set; }
[JsonProperty("response")]
public Response Response { get; set; }
}
public class Response
{
[JsonProperty("numFound")]
public long NumFound { get; set; }
[JsonProperty("start")]
public long Start { get; set; }
[JsonProperty("docs")]
public List<Doc> Docs { get; set; }
}
public class Doc
{
[JsonProperty("tstamp")]
public DateTimeOffset Tstamp { get; set; }
[JsonProperty("digest")]
public string Digest { get; set; }
[JsonProperty("boost")]
public double Boost { get; set; }
[JsonProperty("id")]
public Uri Id { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("url")]
public Uri Url { get; set; }
[JsonProperty("content")]
public string Content { get; set; }
[JsonProperty("_version_")]
public double Version { get; set; }
}
public class ResponseHeader
{
[JsonProperty("status")]
public long Status { get; set; }
[JsonProperty("QTime")]
public long QTime { get; set; }
[JsonProperty("params")]
public Params Params { get; set; }
}
public class Params
{
[JsonProperty("q")]
public string Q { get; set; }
}
And you should parse your json data to C# like this:
var myData = JsonConvert.DeserializeObject<WebRequestResult>(responseBody);
You can generate your C# classes from app.quicktype.io
I know people asked and already got some answers very similar question before like this, but still, I couldn't figure it out about mine. I have a JSON file contains a multidimensional object, like below:
{
"Common": {
"Required": "Required Entry ",
"Photos": "Photos",
"Videos": "Videos",
"Register": "Register"
},
"Forms": {
"Form": "Forms",
"Name": "Name",
"Phone": "Phone",
"Email": "Email",
"Message": "Message"
},
"Sections": {
"Home": {
"EventDateTime": "",
"MainTitle": "",
"SubTitle": ""
},
"About": {},
"Venue": {},
"Schedule": {},
"Speakers": {},
"Sponsors": {},
"Price": {},
"Contact": {}
}
}
I would like to deserialize it into my view model (LanguagesViewModel) like this:
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class LanguagesViewModel
{
public Common Common { get; set; }
public Buttons Buttons { get; set; }
public Forms Forms { get; set; }
public Navbar Navbar { get; set; }
public Sections Sections { get; set; }
}
public class Common
{
public string Required { get; set; }
public string Photos { get; set; }
public string Videos { get; set; }
public string Register { get; set; }
}
public class Forms
{
public string Form { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Message { get; set; }
}
public class Sections
{
public Home Home { get; set; }
public About About { get; set; }
public Venue Venue { get; set; }
public Schedule Schedule { get; set; }
public Speakers Speakers { get; set; }
public Sponsors Sponsors { get; set; }
public Price Price { get; set; }
public Contact Contact { get; set; }
}
public class Home
{
public string EventDateTime { get; set; }
public string MainTitle { get; set; }
public string SubTitle { get; set; }
}
public class About
{
}
public class Venue
{
}
public class Schedule
{
}
public class Speakers
{
}
public class Sponsors
{
}
public class Price
{
}
public class Contact
{
}
}
Some of the snippet to do this:
using (StreamReader sr = new StreamReader(language_file_path))
{
string contents = sr.ReadToEnd();
items = JsonConvert.DeserializeObject<LanguagesViewModel>(contents);
}
Somehow, I only can get the first level of the objects, which is:
LanguagesViewModel{
Common:null,
Forms:null,
Sections:null
}
Not the second level, not the third level. Did I do something wrong or have I missed something? Very appreciated for any kind of help.
Thank you.
You can Use this static class
public static class JsonHelper
{
public static T ToObject<T>(this string content)
{
var obj = JObject.Parse(content).GetValue(typeof(T).Name);
if (obj == null)
throw new NullReferenceException();
else
return obj.ToObject<T>();
//This ToObject here is default method written in object
}
}
Usage
var mymodel= json.ToObject<Forms>();
Or create a JSON object and read it with magic strings.
//Creating your JSON object
JObject content = JObject.Parse(sr.ReadToEnd()//or your json);
//content["your object name"] let you access to you object
var common =(Common)content["Common"];
in multidimensional objects, you can access them like this.
//content["level1"]["level2"]["level3"] & ...
var sections= (Home)content["Sections"]["Home"];
Also this way may work but i prefer the way with magic strings.
dynamic jsonObject = new JObject.Parse(sr.ReadToEnd());
var common = jsonObject.Common;
You can find more in this link
I hope this Helps!
This question already has answers here:
How can I deserialize JSON with C#?
(19 answers)
Closed 4 years ago.
I need to retrieve specific values from API response. My response looks like one below. How can I access to [productCodeScheme] value of each pack?
dynamic api = JObject.Parse(response.Content);
// api contains
{
"operationCode": "12200000",
"packs": [
{
"pack": {
"productCodeScheme": "ppn",
"productCode": "15000436574634",
"serialNumber": "0000000001",
"batchId": "00001",
"expiryDate": "201201"
},
"result": {
"operationCode": "61020008",
"warning": "The product code is invalid."
}
},
{
"pack": {
"productCodeScheme": "gs1",
"productCode": "15000436574634",
"serialNumber": "0000000002",
"batchId": "00001",
"expiryDate": "201201"
},
"result": {
"operationCode": "11310300",
"information": "The pack has been marked as stolen.",
"state": "Stolen"
}
}
]
}
If you want your object to stay dynamic, you could just do
dynamic result = JsonConvert.DeserializeObject<dynamic>(response.Content);
after, you can access the objects inside like below:
foreach(dynamic item in result.packs)
{
string productCodeScheme = item.pack.productCodeScheme.ToString();
}
However, i would strongly suggest that you to deserialize your JSON responses into defined objects instead of using dynamic. dynamics are both insecure and inefficient. You can do someting like example below,
public class PackDetails
{
public string productCodeScheme { get; set; }
public string productCode { get; set; }
public string serialNumber { get; set; }
public string batchId { get; set; }
public string expiryDate { get; set; }
}
public class Result
{
public string operationCode { get; set; }
public string warning { get; set; }
public string information { get; set; }
public string state { get; set; }
}
public class Pack
{
public PackDetails pack { get; set; }
public Result result { get; set; }
}
public class ResponseObject
{
public string operationCode { get; set; }
public List<Pack> packs { get; set; }
}
then you can deserialize a ResponseObject like below and use it
var responseObject = JsonConvert.DeserializeObject<ResponseObject>();
foreach(PackDetails item in responseObject.packs)
{
string productCodeScheme = item.pack.productCodeScheme;
}
I've been searching and trying to get this to work for hours and i'm completely out of ideas. I have JSON text that i'm trying to read and can't see it get it to work. Here is the JSON text.
[ {
"first_aired": "2018-03-03T01:00:00.000Z",
"episode": {
"season": 3,
"number": 13,
"title": "Warning Shot",
"ids": {
"trakt": 2814272,
"tvdb": 6445735,
"imdb": "tt7462514",
"tmdb": 1429184,
"tvrage": 0
}
},
"show": {
"title": "Blindspot",
"year": 2015,
"ids": {
"trakt": 98980,
"slug": "blindspot",
"tvdb": 295647,
"imdb": "tt4474344",
"tmdb": 62710,
"tvrage": 44628
}
} }, {
"first_aired": "2018-03-03T01:00:00.000Z",
"episode": {
"season": 2,
"number": 16,
"title": "Hammock + Balcony",
"ids": {
"trakt": 2874663,
"tvdb": 6535389,
"imdb": "tt7820776",
"tmdb": 1428050,
"tvrage": 0
}
},
"show": {
"title": "MacGyver",
"year": 2016,
"ids": {
"trakt": 107792,
"slug": "macgyver-2016",
"tvdb": 311902,
"imdb": "tt1399045",
"tmdb": 67133,
"tvrage": {}
}
} } ]
I'm trying to get the "episode -> season" and "episode - > number"
This is the code ive been working with and also a fiddle below.
string json = "[{\"first_aired\":\"2018-03-03T01:00:00.000Z\",\"episode\":{\"season\":3,\"number\":13,\"title\":\"Warning Shot\",\"ids\":{\"trakt\":2814272,\"tvdb\":6445735,\"imdb\":\"tt7462514\",\"tmdb\":1429184,\"tvrage\":0}},\"show\":{\"title\":\"Blindspot\",\"year\":2015,\"ids\":{\"trakt\":98980,\"slug\":\"blindspot\",\"tvdb\":295647,\"imdb\":\"tt4474344\",\"tmdb\":62710,\"tvrage\":44628}}},{\"first_aired\":\"2018-03-03T01:00:00.000Z\",\"episode\":{\"season\":2,\"number\":16,\"title\":\"Hammock + Balcony\",\"ids\":{\"trakt\":2874663,\"tvdb\":6535389,\"imdb\":\"tt7820776\",\"tmdb\":1428050,\"tvrage\":0}},\"show\":{\"title\":\"MacGyver\",\"year\":2016,\"ids\":{\"trakt\":107792,\"slug\":\"macgyver-2016\",\"tvdb\":311902,\"imdb\":\"tt1399045\",\"tmdb\":67133,\"tvrage\":null}}}]";
JArray obj = Newtonsoft.Json.JsonConvert.DeserializeObject<JArray>(json);
foreach (var result in obj)
{
foreach (JObject tvshow in result["episode"])
{
string season_num = (string)tvshow["season"];
string episode_num = (string)tvshow["number"];
Console.WriteLine(season_num + " - " + episode_num );
}
}
https://dotnetfiddle.net/speUyL
Thank's for any help anyone can give me!
You actually have nested objects, so you will need to first extract the episode object and then from the episode you can access it's properties which are number and season etc:
foreach (var result in obj)
{
var episode = result["episode"];
Console.WriteLine(episode["season"]);
Console.WriteLine(episode["number"]);
}
This prints the result you are trying to do. Following is the updated fiddle demo:
https://dotnetfiddle.net/WN545C
A easy approach is to have DTO c# classes for your json and then Deserialize the json result in to List<T>. The classes for your json would be :
public class Ids
{
public int trakt { get; set; }
public int tvdb { get; set; }
public string imdb { get; set; }
public int tmdb { get; set; }
public int tvrage { get; set; }
}
public class Episode
{
public int season { get; set; }
public int number { get; set; }
public string title { get; set; }
public Ids ids { get; set; }
}
public class Ids2
{
public int trakt { get; set; }
public string slug { get; set; }
public int tvdb { get; set; }
public string imdb { get; set; }
public int tmdb { get; set; }
public object tvrage { get; set; }
}
public class Show
{
public string title { get; set; }
public int year { get; set; }
public Ids2 ids { get; set; }
}
public class Season
{
public DateTime first_aired { get; set; }
public Episode episode { get; set; }
public Show show { get; set; }
}
An easy way to get the classes generated is by using Json2CSharp.com or either using the Visual Studio feature which can paste JSON as C# classes using Paste Special.
and now you can deserialize and access each season data more better way:
var seasons = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Season>>(json);
foreach (var season in seasons)
{
Console.WriteLine(season.episode.title);
Console.WriteLine(season.first_aired);
Console.WriteLine(season.episode.season);
Console.WriteLine(season.episode.number);
}
You can play with the demo for that here:
https://dotnetfiddle.net/hukLQI
We have to do some changes in existing JSON response and it requires to modify existing c# code too. Till now I've tried but don't get the exact idea about the formatting as it is new for me.
Can any one please check and suggest the changes in below code?
Existing JSON message:
"hotel_room_types": {
"QUEEN": {
"code": "QUEEN",
"bed_type": {
"standard": [
5
],
"custom": []
},
"extra_bed_type": {
"standard": [
5
],
"custom": []
},
"accessibility": "compliant_with_local_laws_for_disabled",
"room_smoking_policy": "non_smoking"
}
}
In above JSON message we have to replace the "bed_type" and "extra_bed_type" with "bed_configurations" and "extra_bed_configurations" in below newly provided format by client:
"hotel_room_types": {
"QUEEN": {
"code": "QUEEN",
"bed_configurations": [
[{
"type": "standard",
"code": 3,
"count": 1
}],
[{
"type": "standard",
"code": 1,
"count": 2
}]
],
"extra_bed_configurations": [
[{
"type": "standard",
"code": 900302,
"count": 1
},
{
"type": "custom",
"name": "Rollaway with wheel locks and adjustable height",
"count": 1
}]
],
"accessibility": "compliant_with_local_laws_for_disabled",
"room_smoking_policy": "non_smoking"
}
}
Existing C# code to generate the JSON response message format:
public class HotelRoomType
{
public string code { get; set; }
public string name { get; set; }
public string description { get; set; }
public List<Photo> photos { get; set; }
public Amenities room_amenities { get; set; }
public string room_size { get; set; }
public string room_size_units { get; set; }
public BedType bed_type { get; set; }
public BedType extra_bed_type { get; set; }
public RoomViewType room_view_type { get; set; }
public string accessibility { get; set; }
public MaxOccupancy max_occupancy { get; set; }
public string room_smoking_policy { get; set; }
}
Below is the code to fill the data in required fields of JSON message its inside a method which contains lines of code so I get it separately:
HotelRoomType hotelrmtype = new HotelRoomType();
hotelrmtype.bed_type = Common.GetStandardBedTypeMappingID(rm.BedType);
if (rm.NumOfBed > 1)
hotelrmtype.extra_bed_type = hotelrmtype.bed_type; //same as bed type
hotelrmtypeDict.Add(rm.Code, hotelrmtype); //Binding Data into Dictionary.
GetStandardBedTypeMappingID() contains :
public static CRS.TripConnect.BedType GetStandardBedTypeMappingID(short code)
{
CRS.TripConnect.BedType tripConnectBedType = new CRS.TripConnect.BedType();
List<int> standardBedTypes = new List<int>();
List<object> customBedTypes = new List<object>();
tripConnectBedType.standard = standardBedTypes;
tripConnectBedType.custom = customBedTypes; //These is blank.
short id = 0;
switch (code)
{
case 10:
id = 3;
break;
case 20: // 20 Queen Q 5
id = 5;
break;
case 30: // 30 Double D 1
id = 1;
break;
case 40: // 40 Twin T 8
id = 8;
break;
}
standardBedTypes.Add(id);
return tripConnectBedType;
}
Update: With the help of #Sam Answer below I have modified the code:
public class HotelRoomType
{
//Added following properties
public List<List<Bed_Configurations>> bed_configurations { get; set; }
public List<List<Extra_Bed_Configurations>> extra_bed_configurations { get; set; }
}
Created two new classes as:
public class Bed_Configurations
{
public string type { get; set; }
public int code { get; set; }
public int count { get; set; }
}
public class Extra_Bed_Configurations
{
public string type { get; set; }
public int code { get; set; }
public int count { get; set; }
public string name { get; set; }
}
Now the question is: How to fill these two list?
I'm trying to achieve this like below but it is giving me conversion error.
Bed_Configurations bdConfig = new Bed_Configurations();
bdConfig.type = "Standard";
bdConfig.code = Common.GetStandardBedTypeMappingIDnew(rm.BedType);
bdConfig.count = rm.NumOfBed;
hotelrmtype.bed_configurations.Add(bdConfig);
Error Message:
Please Advise the changes in the above code so as to get the required JSON message. Appreciate your help!
public class RootClass
{
public HotelRoomType hotel_room_types { get; set; }
}
public class HotelRoomType
{
public BedModelAndDetails QUEEN { get;set; }
}
public class BedModelAndDetails
{
public string accessibility { get; set; }
public string room_smoking_policy { get; set; }
public string code { get; set; }
//public BedType bed_type { get; set; }
public object bed_type { get; set; }
//public BedType extra_bed_type { get; set; }
public object extra_bed_type { get; set; }
public List<List<BedConfiguration>> bed_configurations { get; set; }
public List<List<BedConfiguration>> extra_bed_configurations { get; set; }
}
public class BedType
{
public List<int> standard { get; set; }
public List<int> custom { get; set; }
}
public class BedConfiguration
{
public string type { get; set; }
public int code { get; set; }
public int count { get; set; }
}
[TestMethod]
public void ReplaceJson()
{
var inputJson1 = "{\"hotel_room_types\": {\"QUEEN\": {\"code\": \"QUEEN\", \"bed_type\": {\"standard\": [5],\"custom\": [] }, \"extra_bed_type\": { \"standard\": [5], \"custom\": [] },\"accessibility\": \"compliant_with_local_laws_for_disabled\", \"room_smoking_policy\": \"non_smoking\" } " +"}}";
var input1 = JsonConvert.DeserializeObject<RootClass>(inputJson1, new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore});
var inputJson2 = "{\"hotel_room_types\": {\"QUEEN\": {\"code\": \"QUEEN\",\"bed_configurations\": [[{\"type\": \"standard\",\"code\": 3,\"count\": 1}],[{\"type\": \"standard\",\"code\": 1,\"count\": 2}]],\"extra_bed_configurations\": [[{\"type\": \"standard\",\"code\": 900302,\"count\": 1},{\"type\": \"custom\",\"name\": \"Rollaway with wheel locks and adjustable height\",\"count\": 1}]],\"accessibility\": \"compliant_with_local_laws_for_disabled\",\"room_smoking_policy\": \"non_smoking\"} }}";
var input2 = JsonConvert.DeserializeObject<RootClass>(inputJson2);
//var finalInput = new RootClass();
//finalInput.hotel_room_types = inputJson1
//input1.hotel_room_types.QUEEN.bed_configurations = input2.hotel_room_types.QUEEN.bed_configurations;
//input1.hotel_room_types.QUEEN.extra_bed_configurations = input2.hotel_room_types.QUEEN.extra_bed_configurations;
input1.hotel_room_types.QUEEN.bed_type = input2.hotel_room_types.QUEEN.bed_configurations;
input1.hotel_room_types.QUEEN.extra_bed_type = input2.hotel_room_types.QUEEN.extra_bed_configurations;
}
Does this help?