• Resolved Daniel P.

    (@danidub)


    Hello, for some meta field migration we are exporting the column data to JSON and then decoding it on the import process. I’m using the official information for the Product CSV Importer & Exporter provided here by WooCommerce.

    The converted data to JSON on the exported CSV looks good, is a valid JSON. The problem is on importing data and decoding it. It seems that for some reason is loosing some escaping slashes and becomes corrupted.

    On the importing preview, where you can map columns to fields, the JSON string is valid also, but when reading it the issue appears. Please find at the end both JSON, you can see that near the <img> tags, slashes are lost.

    On import I’m using the same example form the article linked at the beginning of this post:

    
    function process_import($object, $data)
    {
        if (!empty($data['yikes_woo_products_tabs'])) {
    		
            $arr = json_decode($data['yikes_woo_products_tabs'], true);		
            $object->update_meta_data('yikes_woo_products_tabs', $arr);
        }
    
        return $object;
    }
    

    Valid JSON that is on the CSV:

    
    [{"title":"MANZANA & CANELA","id":"manzana-canela","content":"<h4>INGREDIENTES<\/h4>\r\nPasta de higo, pasta de d\u00e1til, semillas de calabazas*, manzana deshidratada troceada*, aceite de girasol*, pasas sultanas* (pasas> 99,5%, aceite de girasol ecol\u00f3gico <0.7%), amino\u00e1cidos ramificados 8:1:1 (L-leucina, L-isoleucina, L-valina), complejo vitam\u00ednico, amilopectina, canela en polvo*, aroma natural de manzana. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.\r\n\r\n[caption id=\"attachment_10252\" align=\"alignnone\" width=\"1226\"]<img class=\"size-full wp-image-10252\" src=\"https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/informacion-nutricional-race-day-bar-manzana-canela.png\" alt=\"Informaci\u00f3n Nutricional Race Day Bar - Manzana & Canela\" width=\"1226\" height=\"980\" \ /> Informaci\u00f3n Nutricional Race Day Bar - Manzana & Canela[\/caption]"},{"title":"BANANA & JENGIBRE","id":"banana-jengibre","content":"<h4>INGREDIENTES<\/h4>\r\nPasta de higo, pasta de d\u00e1til, banana flakes, aceite de girasol*, amilopectina, amino\u00e1cidos ramificados 8:1:1 (L-leucina, L-isoleucina, L-valina), semillas de calabaza*, complejo vitam\u00ednico, jengibre en polvo*, aroma natural de pl\u00e1tano. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.\r\n\r\n[caption id=\"attachment_10251\" align=\"alignnone\" width=\"1228\"]<img class=\"size-full wp-image-10251\" src=\"https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/informacion-nutricional-race-day-bar-banana-jengibre.png\" alt=\"Informaci\u00f3n Nutricional Race Day Bar - Banana & Jengibre\" width=\"1228\" height=\"986\" \ /> Informaci\u00f3n Nutricional Race Day Bar - Banana & Jengibre[\/caption]"},{"title":"CHOCOLATE NEGRO","id":"chocolate-negro","content":"<h4 style=\"font-weight: 500; color: #000000;\">INGREDIENTES<\/h4>\r\n<p style=\"font-weight: 500; color: #000000;\">Pasta de higo, pasta de d\u00e1til, cacao en polvo desgrasado natural, semillas de calabaza*, aceite de girasol*, pasas sultanas* (pasas > 99.5%, aceite de girasol ecol\u00f3gico < 0.7%)*, pepitas de chocolate* (pasta de cacao > 50%, az\u00facar de ca\u00f1a ecol\u00f3gica, manteca de cacao, emulsificante: lecitina de soja)*, aroma natural de chocolate, amilopectina, amino\u00e1cidos ramificados 8:1:1 (L-leucina, L-isoleucina, L-valina), complejo vitam\u00ednico. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.<\/p>\r\n\r\n\r\n[caption id=\"attachment_10250\" align=\"alignnone\" width=\"1232\"]<img class=\"size-full wp-image-10250\" src=\"https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/informacion-nutricional-race-day-bar-chocolate-negro.png\" alt=\"Informaci\u00f3n Nutricional Race Day Bar - Chocolate Negro\" width=\"1232\" height=\"986\" \ /> Informaci\u00f3n Nutricional Race Day Bar - Chocolate Negro[\/caption]"},{"title":"CHOCOLATE BLANCO Y FRESA","id":"chocolate-blanco-y-fresa","content":"<h4 style=\"font-weight: 500; color: #000000;\">INGREDIENTES<\/h4>\r\n<span style=\"font-weight: 500; color: #000000;\">Pasta de higo, pasta de d\u00e1til*, fresa en polvo, semillas de calabaza*, pepitas de chocolate blanco (leche, soja), aceite de girasol*, complejo vitam\u00ednico, amilopectina de arroz, aroma natural de fresa. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.<\/span>\r\n\r\n[caption id=\"attachment_16031\" align=\"alignnone\" width=\"500\"]<img class=\"wp-image-16031 \" src=\"https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/valor-nutricional-race-day-bar-chocolate-blanco-fresa.png\" alt=\"Valor Nutricional Race Day Bar - Chocolate Blanco y Fresa\" width=\"500\" height=\"411\" \ /> Valor Nutricional Race Day Bar - Chocolate Blanco y Fresa[\/caption]"},{"title":"LIM\u00d3N","id":"limon","content":"<h4 style=\"font-weight: 500; color: #000000;\">INGREDIENTES<\/h4>\r\n<span style=\"font-weight: 500; color: #000000;\">Pasta de higo, pasta de d\u00e1til*, pepitas de chocolate negro*(soja), semillas de calabaza*, lim\u00f3n en flakes, aceite de girasol*, lim\u00f3n en polvo, complejo vitam\u00ednico, amilopectina de arroz. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.<\/span>\r\n\r\n[caption id=\"attachment_16032\" align=\"alignnone\" width=\"500\"]<img class=\"wp-image-16032 \" src=\"https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/valor-nutricional-race-day-bar-limon.png\" alt=\"Valor Nutricional Race Day Bar - Lim\u00f3n\" width=\"500\" height=\"413\" \ /> Valor Nutricional Race Day Bar - Lim\u00f3n[\/caption]"}]
    

    Invalid JSON when processing the import process:

    
    [{"title":"MANZANA & CANELA","id":"manzana-canela","content":"<h4>INGREDIENTES\r\nPasta de higo, pasta de d\u00e1til, semillas de calabazas*, manzana deshidratada troceada*, aceite de girasol*, pasas sultanas* (pasas> 99,5%, aceite de girasol ecol\u00f3gico <0.7%), amino\u00e1cidos ramificados 8:1:1 (L-leucina, L-isoleucina, L-valina), complejo vitam\u00ednico, amilopectina, canela en polvo*, aroma natural de manzana. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.\r\n\r\n[caption id=\"attachment_10252\" align=\"alignnone\" width=\"1226\"]<img class="size-full wp-image-10252" src="https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/informacion-nutricional-race-day-bar-manzana-canela.png" alt="Informaci\u00f3n Nutricional Race Day Bar - Manzana & Canela" width="1226" height="980" /> Informaci\u00f3n Nutricional Race Day Bar - Manzana & Canela[\/caption]"},{"title":"BANANA & JENGIBRE","id":"banana-jengibre","content":"<h4>INGREDIENTES\r\nPasta de higo, pasta de d\u00e1til, banana flakes, aceite de girasol*, amilopectina, amino\u00e1cidos ramificados 8:1:1 (L-leucina, L-isoleucina, L-valina), semillas de calabaza*, complejo vitam\u00ednico, jengibre en polvo*, aroma natural de pl\u00e1tano. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.\r\n\r\n[caption id=\"attachment_10251\" align=\"alignnone\" width=\"1228\"]<img class="size-full wp-image-10251" src="https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/informacion-nutricional-race-day-bar-banana-jengibre.png" alt="Informaci\u00f3n Nutricional Race Day Bar - Banana & Jengibre" width="1228" height="986" /> Informaci\u00f3n Nutricional Race Day Bar - Banana & Jengibre[\/caption]"},{"title":"CHOCOLATE NEGRO","id":"chocolate-negro","content":"<h4 style="font-weight: 500;color: #000000">INGREDIENTES\r\n<p style="font-weight: 500;color: #000000">Pasta de higo, pasta de d\u00e1til, cacao en polvo desgrasado natural, semillas de calabaza*, aceite de girasol*, pasas sultanas* (pasas > 99.5%, aceite de girasol ecol\u00f3gico < 0.7%)*, pepitas de chocolate* (pasta de cacao > 50%, az\u00facar de ca\u00f1a ecol\u00f3gica, manteca de cacao, emulsificante: lecitina de soja)*, aroma natural de chocolate, amilopectina, amino\u00e1cidos ramificados 8:1:1 (L-leucina, L-isoleucina, L-valina), complejo vitam\u00ednico. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.\r\n\r\n\r\n[caption id=\"attachment_10250\" align=\"alignnone\" width=\"1232\"]<img class="size-full wp-image-10250" src="https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/informacion-nutricional-race-day-bar-chocolate-negro.png" alt="Informaci\u00f3n Nutricional Race Day Bar - Chocolate Negro" width="1232" height="986" /> Informaci\u00f3n Nutricional Race Day Bar - Chocolate Negro[\/caption]"},{"title":"CHOCOLATE BLANCO Y FRESA","id":"chocolate-blanco-y-fresa","content":"<h4 style="font-weight: 500;color: #000000">INGREDIENTES\r\n<span style="font-weight: 500;color: #000000">Pasta de higo, pasta de d\u00e1til*, fresa en polvo, semillas de calabaza*, pepitas de chocolate blanco (leche, soja), aceite de girasol*, complejo vitam\u00ednico, amilopectina de arroz, aroma natural de fresa. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.\r\n\r\n[caption id=\"attachment_16031\" align=\"alignnone\" width=\"500\"]<img class="wp-image-16031 " src="https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/valor-nutricional-race-day-bar-chocolate-blanco-fresa.png" alt="Valor Nutricional Race Day Bar - Chocolate Blanco y Fresa" width="500" height="411" /> Valor Nutricional Race Day Bar - Chocolate Blanco y Fresa[\/caption]"},{"title":"LIM\u00d3N","id":"limon","content":"<h4 style="font-weight: 500;color: #000000">INGREDIENTES\r\n<span style="font-weight: 500;color: #000000">Pasta de higo, pasta de d\u00e1til*, pepitas de chocolate negro*(soja), semillas de calabaza*, lim\u00f3n en flakes, aceite de girasol*, lim\u00f3n en polvo, complejo vitam\u00ednico, amilopectina de arroz. *Proviene de agricultura ecol\u00f3gica. Sin ingredientes animales. No GMO.\r\n\r\n[caption id=\"attachment_16032\" align=\"alignnone\" width=\"500\"]<img class="wp-image-16032 " src="https:\/\/findyoureverest.es\/wp-content\/uploads\/2020\/03\/valor-nutricional-race-day-bar-limon.png" alt="Valor Nutricional Race Day Bar - Lim\u00f3n" width="500" height="413" /> Valor Nutricional Race Day Bar - Lim\u00f3n[\/caption]"}]
    

    Any ideas why is this happening?
    Thank you.

    • This topic was modified 3 years, 3 months ago by Daniel P..
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hey @danidub,

    The converted data to JSON on the exported CSV looks good, is a valid JSON. The problem is on importing data and decoding it. It seems that for some reason is loosing some escaping slashes and becomes corrupted.

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    I hope that helps!

    Kind regards,

    Thread Starter Daniel P.

    (@danidub)

    Hello @martynmjones, I have solved my issue using another strategy to read the custom meta from the product $object instead of the $data.

    If I read the meta field from the product $object I can decode the JSON without any issues, but if I read it from $data it seems to be corrupted.

    So the original problem is still there.

    Thank you for your comments.

    Mirko P.

    (@rainfallnixfig)

    Hi @danidub

    Thanks for the update!

    For development-oriented questions like yours, the channels mentioned above by my colleague are the right ones to get in touch with the developers who are best placed to help you find a solution.

    Kindly note that this forum is mostly focused on resolving issues with core configuration and its intended functionality but we’ll leave this thread open for a little longer in case a developer wants to step in to help you out.

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    We’ve not seen any activity on this thread for a while, so I’m marking this thread as resolved.

    Hopefully, you were able to find a solution and the above resources for developers were helpful. If you have further questions, please feel free to open a new topic.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom import/export columns from CSV to JSON missing slashes’ is closed to new replies.