Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Parse JSON String in column

Hi,

How is possible to parse JSON string in the column to several columns?

 

6 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    You should be able to use the Json.Document function to parse the JSON.  Depending on the structure, you will likely be able to expand the contained Records and/or Lists.

    Regards,

    Pat

  • Jimmy801's avatar
    Jimmy801
    Community Champion

    Hello Anonymous 

     

    you can use Table.TransformColumns or even better Table.TransformRows to loop through your data and applying a Json.Document on every cell. Surround it by try otherwise to handle empty rows or non-json-cells

     

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy

  • v-alq-msft's avatar
    v-alq-msft
    Community Support

    Hi, Anonymous 

     

    You may try adding a new step with the following m codes.

    =Table.TransformColumns(#"Last Step",{{"device",Json.Document},{"geo",Json.Document},
    {"app_info",Json.Document}})

     

    Then you may expand the column to get the corresponding result.

     

    For further information, please refer to the following link.

    Convert JSON strings to tables in Power Query/ Power BI 

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • CNENFRNL's avatar
      CNENFRNL
      Community Champion

      Hi, v-alq-msft , you might want to simply the code this way if the table consists of too many columns

      = Function.Invoke(Table.TransformColumns, {#"Last Step", List.Accumulate(Table.ColumnNames(#"Last Step"), {}, (s,c)=>s&{{c,Json.Document}})})
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi,
      Where I need to add  "New Step"?

      • v-alq-msft's avatar
        v-alq-msft
        Community Support

        Hi, Anonymous 

         

        You may right click the last step of the query and click 'Insert Step After' like below.

         

        Best Regards

        Allan