Removing quotes from returned CSV file
(cols[0]).replace(/"/g, "") before years.push(cols[0]) statement will do, if you are only having problem with double quotes.
remove outer double quotes from array of strings
The real solution is fix whatever is producing invalid JSON and make it valid.
If you can not fix it, you can manipulate the data as long as you can say that the content will not have any quotes, a simple replace can fix it.
var x = "['a', 'b', 'c']";
var obj = JSON.parse(x.replace(/'/g,'"'));
console.log(obj);
remove quotes around ONLY numeric values in string
I'd parse the JSON and use a reviver function to replace digit strings with just the digits:
var arr= '[{"a":"b","c":"521"}]';
const parsed = JSON.parse(
arr,
(key, value) => typeof value === 'string' && /^\d+$/.test(value)
? Number(value)
: value
);
console.log(JSON.stringify(parsed));
Remove white space inside single quotes before and after text inside the quotes
Lookahead for exactly one '
before the end of the string:
const input = `testName=' test '`;
const cleaned = input.replace(/ +(?=[^']*'$)/g, '');
console.log(cleaned);
Removing double-quotes around Keys in Array
When you write JSON.stringify to convert it in the string, it would add the double quotes to your keys.
You just have to write obj directly, it would behave as the normal object and not string.
So please update your code of lines with the below code. It should resolve your problem.
var obj = {};
obj.Firstname = document.getElementById("firstName").value;
obj.Lastname = document.getElementById("surname").value;
var jsonStringObj = {users: [obj]};
console.log(jsonStringObj)
Related Topics
Show Multiple Divs on Button Click
Looping Through a Json Object Containing More Objects and Arrays
Updating Array in Object Properties Using Property'S Name
How to Wait for Element to Disappear in Cypress
Jquery Click Events Firing Multiple Times
Reactjs: Expected Onclick Listener to Be a Function, Instead Got Type String
How to Count the Entire Number of Rows in a Datatable
How to Mock a Fake Database for When Unit Testing Against Knex
How to Clear All Input Fields in Bootstrap Modal When Clicking Data-Dismiss Button
Node.Js MySQL Query in a for Loop
How to Format Numbers in Vuejs
Reactjs - Multiple If Conditions Inside Map Function
Call 2 Functions Within Onchange Event
How to Change Image Source on Hover Using Javascript, But Applies to Each Individual Photo
Get Image from Json File Using JavaScript and Display in HTML Img Tag
How to Create a Remember Me Function in Login Without Using Form in JavaScript or Jquery
How to Count Unique Value from Object of Array in JavaScript