locked
Convert Multi-Row JSON to a Datatable RRS feed

  • Question

  • I have users pasting in a JSON string into a textbox for my application to process. I need to take the JSON string and process it into a datatable for further downstream processing. I develop in vb.net. An example string is shown below. The string will always have seven columns and x number of rows.

    I have about 12+ hours searching google attempting to figure this out so far. I suspect I am not asking the right questions. I am familiar will creating and decoding single object JSON. Having a tough time doing anything with multiple objects. Any help here would be greatly appreciated.

    Thank you!


    [

            {
                    "Id": "001",

                    "Event ID": 1001,

                    "Zip Code": "75035",

                    "CalcVal": "50.5%",

                    "City based on Zipcode": "Frisco",

                    "State": "TX",

                    "County": "Collin"

            },
      {
                    "Id": "002",

                    "Event ID": 1002,

                    "Zip Code": "75019",

                    "CalcVal": "50.5%",

                    "City based on Zipcode": "Coppell",

                    "State": "TX",

                    "County": "Dallas"

            },
      {
                    "Id": "003",

                    "Event ID": 1003,

                    "Zip Code": "75252",

                    "CalcVal": "50.5%",

                    "City based on Zipcode": "Dallas",

                    "State": "TX",

                    "County": "Dallas"

            }
    ]

    Thursday, June 25, 2020 4:29 PM

Answers

  • Use Json.net

    Imports Newtonsoft.Json
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            DataGridView1.DataSource = JsonConvert.DeserializeObject(Of DataTable)(TextBox1.Text)
        End Sub
    End Class
    

    https://www.nuget.org/packages/Newtonsoft.Json/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, June 25, 2020 5:02 PM

All replies

  • Use Json.net

    Imports Newtonsoft.Json
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            DataGridView1.DataSource = JsonConvert.DeserializeObject(Of DataTable)(TextBox1.Text)
        End Sub
    End Class
    

    https://www.nuget.org/packages/Newtonsoft.Json/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, June 25, 2020 5:02 PM
  • Karen, 

    Wow that was quick. I have a really tight deadline. This helps tremendously. Thank you very much!

    Thursday, June 25, 2020 5:23 PM
  • Karen, 

    Wow that was quick. I have a really tight deadline. This helps tremendously. Thank you very much!

    Your welcome :-)

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, June 25, 2020 5:33 PM