Click here to Skip to main content
13,899,467 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have a JSON string in which items coming in single quote but i want to remove these single quote from items from javaScript.

below string is given-

" [{
       'id': '0.0',
       'parent': '',
       'name': 'National'
   }, {
       'id': '1.1',
       'parent': '0.0',
       'name': 'C1',
       'value': 4286
   }, {
       'id': '1.2',
       'parent': '0.0',
       'name': 'C2',
       'value': 4258
   }, {
       'id': '1.3',
       'parent': '0.0',
       'name': 'C3',
       'value': 3150
   }, {
       'id': '1.4',
       'parent': '0.0',
       'name': 'C4'
   }, {
       'id': '1.5',
       'parent': '0.0',
       'name': 'C5',
       'value': 2958
   }, {
       'id': '1.6',
       'parent': '0.0',
       'name': 'C6',
       'value': 6295
   }, {
       'id': '1.7',
       'parent': '0.0',
       'name': 'C7',
       'value': 8629
   }, {
       'id': '1.8',
       'parent': '0.0',
       'name': 'C8',
       'value': 3958
   }
   ] "


I want below output ----


" [{
       id: 0.0,
       parent: ,
       name: National
   }, {
       id: 1.1,
       parent: 0.0,
       name: C1,
       value: 4286
   }, {
       id: 1.2,
       parent: 0.0,
       name: C2,
       value: 4258
   }, {
       id: 1.3,
       parent: 0.0,
       name: C3,
       value: 3150
   }, {
       id: 1.4,
       parent: 0.0,
       name: C4
   }, {
       id: 1.5,
       parent: 0.0,
       name: C5,
       value: 2958
   }, {
       id: 1.6,
       parent: 0.0,
       name: C6,
       value: 6295
   }, {
       id: 1.7,
       parent: 0.0,
       name: C7,
       value: 8629
   }, {
       id: 1.8,
       parent: 0.0,
       name: C8,
       value: 3958
   }
   ] "

Please suggest..

What I have tried:

I have tried using javascript but don't get desired result.
Posted
Updated 27-Aug-18 19:55pm
v2
Comments
Bryian Tan 28-Aug-18 1:22am
   
can you share the code?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hello Suneel,

Please use below code to remove all single quote from the string.
var str = "[{'id': '0.0','parent': 'none','name': 'National'}]";
str.replace(/\'/gi,'')

Here is the output
"[{id: 0.0,parent: none,name: National}]"


Regards,
Imdadhusen
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Anyway, you didn't post the code to remove the single quote. Here what I would suggest

var x = " [{'id': '0.0','parent': '','name': 'National'},{'id': '1.1', 'parent': '0.0','name': 'C1','value': 4286}] ";

var y = x.replace(/'/g, "");


Output:
[{id: 0.0,parent: ,name: National},{id: 1.1, parent: 0.0,name: C1,value: 4286}]
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

string jsonstr = @" [{
      'id': '0.0',
      'parent': '',
      'name': 'National'
  }, {
      'id': '1.1',
      'parent': '0.0',
      'name': 'C1',
      'value': 4286
  }, {
      'id': '1.2',
      'parent': '0.0',
      'name': 'C2',
      'value': 4258
  }, {
      'id': '1.3',
      'parent': '0.0',
      'name': 'C3',
      'value': 3150
  }, {
      'id': '1.4',
      'parent': '0.0',
      'name': 'C4'
  }, {
      'id': '1.5',
      'parent': '0.0',
      'name': 'C5',
      'value': 2958
  }, {
      'id': '1.6',
      'parent': '0.0',
      'name': 'C6',
      'value': 6295
  }, {
      'id': '1.7',
      'parent': '0.0',
      'name': 'C7',
      'value': 8629
  }, {
      'id': '1.8',
      'parent': '0.0',
      'name': 'C8',
      'value': 3958
  }
  ] ";

           jsonstr = jsonstr.Replace("'", "");
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190306.1 | Last Updated 28 Aug 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100