0

HOW CAN I CONVERT THIS CSV FILE TO A NESTED JSON?

date                model code              value
==================================================
15-01-2017 00:00    EMA_EPD1_PTG_NUS_DPG    2.138
15-01-2017 00:00    EMA_EPD2_PTG_NUS_DPG    1.75
15-02-2017 00:00    EMA_EPD1_PTG_NUS_DPG    2.19
15-02-2017 00:00    EMA_EPD2_PTG_NUS_DPG    1.757

My desired Json format is like that : How can I achieve this kind of nested Json. i will use this Json to validate data by walking on dates then models and then at last the values.

"date": 15-01-2017 00:00 { 
                          [
                           { "model_code" : EMA_EPD1_PTG_NUS_DPG [
                                                                  {
                                                                  "value" :2.138 
                                                                  }
                                                                 ]
                           },
                           { "model_code" :EMA_EPD2_PTG_NUS_DPG [
                                                                  {
                                                                  "value" : 1.75 
                                                                  }
                                                                 ]
                           }
                         ]

"date": 15-02-2017 00:00 { 
                          [
                           { "model_code" : EMA_EPD1_PTG_NUS_DPG [
                                                                  {
                                                                  "value" :2.19 
                                                                  }
                                                                 ]
                           },
                           { "model_code" :EMA_EPD2_PTG_NUS_DPG [
                                                                 {
                                                                 "value" : 1.757 
                                                                  }
                                                                 ]
                           }
                         ]                                                          
  • That is not JSON. – Alex Hall Apr 22 '18 at 09:18
  • You should check the documentation first before posting here, there's a function to_json in pandas dataframe. Also if you want a particular kind of JSON you should try to make it on your own by observing the basic block whether it is a list or dictionary and then doing so for the rest. – Jack Daniels Apr 23 '18 at 05:19

0 Answers0