0

I have following json:

{
    "Name" : "Value1",
    "Data": [
        {
            "UserName": "test",
            "email": "[email protected]",
            "UserInformation": {
                "City": "city",
                "country:": "country"
            }
        },        
        {
            "UserName": "test1",
            "email": "[email protected]"
        }
    ]
}

I want get next dictionary:

{
    "Name" : "Value1",
    "Data[0].UserName": "test",
    "Data[0].email": "[email protected]",
    "Data[0].UserInformation.City": "city",
    "Data[0].UserInformation.country": "country",
    "Data[1].UserName": "test1",
    "Data[1].email": "[email protected]"
}

Using Newtonsoft.Json don't help resolving my problem. Please, can you help me?

1
  • That's some odd requirement. Have you seen json2csharp? This site can convert your JSON to C# classes which you can use to deserialize your JSON. Commented Aug 19, 2020 at 12:35

1 Answer 1

2

If I understood correctly you are looking for something like this (using Newtonsoft.Json):

var dictionary = JObject.Parse(json)
    .Descendants()
    .OfType<JValue>()
    .ToDictionary(jv => jv.Path, jv => jv.ToString());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.