My json:
{ "question_1":
{ "type" : "string"
, "title" : "1. 1. What did he want to make for dinner?"
, "enum":
[ " a.) He wanted to make some salad and spaghetti"
, " b.) He wanted to make some pasta salad"
]
, "required": false
}
, "question_2":
{ "type": "string"
, "title": "2. 2. Did he have the ingredients to make dinner?"
, "enum":
[ " a.) Yes, he had the ingredients"
, " b.) No, he didn't have the ingredients"
]
, "required": false
}
, "question_3":
{ "type" : "string"
, "title" : "3. 3. Where did he go shopping?"
, "enum":
[ " a.) He went to Albertsons"
, " b.) He went to Albertos"
]
, "required": false
}
}
in my json there are many numbers next to each other and are duplicated
Eg:
1. 1. => 1.
2. 2. => 2.
3. 3. => 3.
and so on
How can i remove this duplication?
I want to remove duplicate numbers next to each other in json
2
Answers
You can replace it using a regex. Using grouping references (the parenthesis around
(d)
form a group of one decimal and the1
refers to it) will make sure that you don’t remove numbers like "1. 2." and allow you to refer to it during replacement:If it actually is JSON, which you are going to parse using
JSON.parse
, you could make use of the optionalreviver
parameter.Expanding on Moritz Ringler’s solution.