Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Format JSON Result

Json data returned from my ASP.NET core server with:

JsonConvert.SerializeObject(categories.Select(t => new { id = t.Id.ToString(), text = t.Name.ToLower() }))

Looks:

[
{
    "id": "7929d7ad-c7c3-45c5-b749-7633a478d55c",
    "text": "apparel"
},
{
    "id": "e551cbc2-9069-4c99-a66b-5824ec2610b2",
    "text": "electronics"
}]

But I want result like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{"results":[
{
    "id": "7929d7ad-c7c3-45c5-b749-7633a478d55c",
    "text": "apparel"
},
{
    "id": "e551cbc2-9069-4c99-a66b-5824ec2610b2",
    "text": "electronics"
}]}

for select2. How can I achieve that?

>Solution :

try this

JsonConvert.SerializeObject( new { 
results = categories.Select(t => new { id = t.Id.ToString(), text = t.Name.ToLower() }) 
} );
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading