I am using Woocommerce API
in node js to import product data from mssql server
db to my woocommerce database.
The recordset, I am getting through ms sql query, contains a images field
.
In Woocommerce API, to import images I need this type of json object
,
var data = {
product: {
title: 'Premium Quality',
type: 'simple',
regular_price: '21.99',
description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
short_description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
categories: [
9,
14
],
**images: [
{
src: 'http://example.com/wp-content/uploads/2015/01/premium-quality-front.jpg',
position: 0
},**
{
src: 'http://example.com/wp-content/uploads/2015/01/premium-quality-back.jpg',
position: 1
}
]
}
};
Rest is fine, but I have issue with images, As I am getting images json in quotes images: '[{...}]'
as the data type is varchar in db table.
Because of this quotes, Images are not inserting in db through Woocommerce rest API.
I want to remove the quote from images specifically. Or any other suggestion.
I am new to node js. Can any one please help.
As far as I understood you problem is you are getting extra
""
at the start and end of a string which specifies the image location.You just have to chop of the first & last character of your string variable in js.
Solution:
Demo :
OR
Demo:
Remove “” from start and end of string :
OR
Refer : remove-double-quotes-from-json-return-data and Can you create a JavaScript string without using ‘ or ” quotes?