0

I am trying to convert a CSV that looks like this:

purchase_order,sku,vendor,qty,boxid
ABC,BARBY,BARBY COMPANY,10,ABC
XYZ,KEN,KEN COMPANY,14,XYZ
WAW,GI JOE,Cobra,WAW

Into a nested JSON structure that looks like this:

  {
      purchase_order:"ABC",
      boxes:[
        {
          boxid:"ABC",
          storeloc:"UK",
          items:[
            {
              sku:"BARBY",
              qty:10
            },
            {
              sku:"Skipper",
              qty:10
            }
          ]
        }

  ],
  vendor:"BARBY COMPANY"
}

I have something that is very similar to this. I'd prefer not to share the exact code because it has sensitive data in it. However, I am not sure how to add another level of nesting. The purchase_order and boxid need to be the same.

Walter Whalen
  • 97
  • 1
  • 8
  • 1
    Why using pandas? Maybe this is for you? https://marshmallow.readthedocs.io/en/stable/ you can use pandas https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_dict.html in between – phylogram Jan 30 '20 at 21:51
  • Familiarity mostlly. Let me look marshmallow a bit more. Thank you. – Walter Whalen Jan 30 '20 at 22:05

0 Answers0