node.js - Remove quotes from a json object value -


i using woocommerce api in node js import product data mssql server db woocommerce database.

the recordset, getting through ms sql query, contains images field.

in woocommerce api, import images need 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 fine, have issue images, getting images json in quotes images: '[{...}]' data type varchar in db table.

because of quotes, images not inserting in db through woocommerce rest api.

i want remove quote images specifically. or other suggestion.

i new node js. can 1 please help.

as far understood problem getting "" @ start , end of string specifies image location. have chop of first & last character of string variable in js.

solution:

var x = string(/'[{...}]'/); str = x.substring(1, x.length - 1); var image = str.substring(1, str.length - 1); 

demo :

function myfunction() {    var x = string(/'[{...}]'/);    str = x.substring(1, x.length - 1);    var res = str.substring(1, str.length - 1);    document.getelementbyid("demo").innerhtml = res;  }
<button onclick="myfunction()">try it</button>    <p id="demo"></p>

or

demo:

remove "" start , end of string :

var somestr = string('[{...}]'); alert(somestr) alert(somestr.replace(/^"(.*)"$/, '$1')); 

var somestr = string('"[{...}]"');  alert(somestr)  alert(somestr.replace(/^"(.*)"$/, '$1'));

or

var test = "\"house\""; console.log(test); console.log(test.replace(/\"/g, ""));  

refer : remove-double-quotes-from-json-return-data , can create javascript string without using ' or " quotes?


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -