Restructure and add key-value pair to json string at run-time using Newtonsoft

I’m trying to deserialize the following json string to a series of custom c# classes below. I’m not sure if this is the right or best approach but short of doing a Find/Replace on the json string(doesn’t seem like a very clean way to do it, there must be a better way than that) I’m not sure what else can be done.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> "Meta Data": {
"1. Information": "Daily Prices (open, high, low, close) and Volumes",
"2. Symbol": "NVDA",
"3. Last Refreshed": "2024-12-06",
"4. Output Size": "Full size",
"5. Time Zone": "US/Eastern"
},
"Time Series (Daily)": {
"2024-12-06": {
"1. open": "144.6000",
"2. high": "145.7000",
"3. low": "141.3100",
"4. close": "142.4400",
"5. volume": "188505573"
},
"2024-12-05": {
"1. open": "145.1100",
"2. high": "146.5400",
"3. low": "143.9500",
"4. close": "145.0600",
"5. volume": "172621180"
},
// Many more entries
</code>
<code> "Meta Data": { "1. Information": "Daily Prices (open, high, low, close) and Volumes", "2. Symbol": "NVDA", "3. Last Refreshed": "2024-12-06", "4. Output Size": "Full size", "5. Time Zone": "US/Eastern" }, "Time Series (Daily)": { "2024-12-06": { "1. open": "144.6000", "2. high": "145.7000", "3. low": "141.3100", "4. close": "142.4400", "5. volume": "188505573" }, "2024-12-05": { "1. open": "145.1100", "2. high": "146.5400", "3. low": "143.9500", "4. close": "145.0600", "5. volume": "172621180" }, // Many more entries </code>
    "Meta Data": {
        "1. Information": "Daily Prices (open, high, low, close) and Volumes",
        "2. Symbol": "NVDA",
        "3. Last Refreshed": "2024-12-06",
        "4. Output Size": "Full size",
        "5. Time Zone": "US/Eastern"
    },
    "Time Series (Daily)": {
        "2024-12-06": {
            "1. open": "144.6000",
            "2. high": "145.7000",
            "3. low": "141.3100",
            "4. close": "142.4400",
            "5. volume": "188505573"
        },
        "2024-12-05": {
            "1. open": "145.1100",
            "2. high": "146.5400",
            "3. low": "143.9500",
            "4. close": "145.0600",
            "5. volume": "172621180"
        },
        // Many more entries

But, I want to rearrange and reorganize the json to:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>"MetaData": {
"Information": "Daily Prices (open, high, low, close) and Volumes",
"Symbol": "NVDA",
"LastRefreshed": "2024-12-06",
"OutputSize": "Full size",
"TimeZone": "US/Eastern"
},
"TimeSeries": {
"Data": {
"open": "144.6000",
"high": "145.7000",
"low": "141.3100",
"close": "142.4400",
"volume": "188505573",
"date": "2024-12-06",
"series": "Daily"
},
"Data": {
"open": "145.1100",
"high": "146.5400",
"low": "143.9500",
"close": "145.0600",
"volume": "172621180",
"date": "2024-12-05",
"series": "Daily"
}
}
</code>
<code>"MetaData": { "Information": "Daily Prices (open, high, low, close) and Volumes", "Symbol": "NVDA", "LastRefreshed": "2024-12-06", "OutputSize": "Full size", "TimeZone": "US/Eastern" }, "TimeSeries": { "Data": { "open": "144.6000", "high": "145.7000", "low": "141.3100", "close": "142.4400", "volume": "188505573", "date": "2024-12-06", "series": "Daily" }, "Data": { "open": "145.1100", "high": "146.5400", "low": "143.9500", "close": "145.0600", "volume": "172621180", "date": "2024-12-05", "series": "Daily" } } </code>
"MetaData": {
            "Information": "Daily Prices (open, high, low, close) and Volumes",
            "Symbol": "NVDA",
            "LastRefreshed": "2024-12-06",
            "OutputSize": "Full size",
            "TimeZone": "US/Eastern"
        },
        "TimeSeries": {
            "Data": {
                "open": "144.6000",
                "high": "145.7000",
                "low": "141.3100",
                "close": "142.4400",
                "volume": "188505573", 
                "date": "2024-12-06",
                "series": "Daily"
            },
            "Data": {
                "open": "145.1100",
                "high": "146.5400",
                "low": "143.9500",
                "close": "145.0600",
                "volume": "172621180",
                "date": "2024-12-05",
                "series": "Daily"
            }
        }

So I can create the following classes

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> public class Data
{
[JsonProperty("open")]
public string open { get; set; }
[JsonProperty("high")]
public string high { get; set; }
[JsonProperty("low")]
public string low { get; set; }
[JsonProperty("close")]
public string close { get; set; }
[JsonProperty("volume")]
public string volume { get; set; }
[JsonProperty("date")]
public string date { get; set; }
[JsonProperty("series")]
public string series { get; set; }
}
public class Root
{
[JsonProperty("MetaData")]
public MetaData MetaData { get; set; }
[JsonProperty("TimeSeries")]
public TimeSeries TimeSeries { get; set; }
}
public class TimeSeries
{
[JsonProperty("Data")]
public Data Data { get; set; }
}
public class MetaData
{
[JsonProperty("Information")]
public string Information { get; set; }
[JsonProperty("Symbol")]
public string Symbol { get; set; }
[JsonProperty("Last Refreshed")]
public string LastRefreshed { get; set; }
[JsonProperty("Output Size")]
public string OutputSize { get; set; }
[JsonProperty("Time Zone")]
public string TimeZone { get; set; }
}
</code>
<code> public class Data { [JsonProperty("open")] public string open { get; set; } [JsonProperty("high")] public string high { get; set; } [JsonProperty("low")] public string low { get; set; } [JsonProperty("close")] public string close { get; set; } [JsonProperty("volume")] public string volume { get; set; } [JsonProperty("date")] public string date { get; set; } [JsonProperty("series")] public string series { get; set; } } public class Root { [JsonProperty("MetaData")] public MetaData MetaData { get; set; } [JsonProperty("TimeSeries")] public TimeSeries TimeSeries { get; set; } } public class TimeSeries { [JsonProperty("Data")] public Data Data { get; set; } } public class MetaData { [JsonProperty("Information")] public string Information { get; set; } [JsonProperty("Symbol")] public string Symbol { get; set; } [JsonProperty("Last Refreshed")] public string LastRefreshed { get; set; } [JsonProperty("Output Size")] public string OutputSize { get; set; } [JsonProperty("Time Zone")] public string TimeZone { get; set; } } </code>
    public class Data
    {
        [JsonProperty("open")]
        public string open { get; set; }

        [JsonProperty("high")]
        public string high { get; set; }

        [JsonProperty("low")]
        public string low { get; set; }

        [JsonProperty("close")]
        public string close { get; set; }

        [JsonProperty("volume")]
        public string volume { get; set; }

        [JsonProperty("date")]
        public string date { get; set; }

        [JsonProperty("series")]
        public string series { get; set; }
    }

    public class Root
    {
        [JsonProperty("MetaData")]
        public MetaData MetaData { get; set; }

        [JsonProperty("TimeSeries")]
        public TimeSeries TimeSeries { get; set; }
    }

    public class TimeSeries
    {
        [JsonProperty("Data")]
        public Data Data { get; set; }
    }

    public class MetaData
    {
        [JsonProperty("Information")]
        public string Information { get; set; }

        [JsonProperty("Symbol")]
        public string Symbol { get; set; }

        [JsonProperty("Last Refreshed")]
        public string LastRefreshed { get; set; }

        [JsonProperty("Output Size")]
        public string OutputSize { get; set; }

        [JsonProperty("Time Zone")]
        public string TimeZone { get; set; }
    }   

This way I could deserialize the json string. I’ve done some research looking in to this but I haven’t found what I’m looking for yet. I’m using Newtonsoft and I’d like answers to use Newtonsoft as well. But, if there is something better out there I’ll be willing to switch to another package. First, I’d like to know if this approach would work. If not, I’d like ideas on how communiy members would tackle this problem.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật