admin管理员组文章数量:1417686
My JSON response values have single quote but I want double quote. I have already tried JSON.stringfy()
and JSON.parse()
, they both are not working.
Response:
[
{
title: 'Car',
price: 2323,
}
]
Expected Response:
[
{
title: "Car",
price: 2323,
}
]
Basically, I want to use that response in shopify graphql query.
mutation {
productCreate(input: {
id:"gid://shopify/Product/4725894742116"
title: "This is a car",
variants:[{
title:"car",
price: 12
}]
}) {
product {
id
}
}
}
My JSON response values have single quote but I want double quote. I have already tried JSON.stringfy()
and JSON.parse()
, they both are not working.
Response:
[
{
title: 'Car',
price: 2323,
}
]
Expected Response:
[
{
title: "Car",
price: 2323,
}
]
Basically, I want to use that response in shopify graphql query.
mutation {
productCreate(input: {
id:"gid://shopify/Product/4725894742116"
title: "This is a car",
variants:[{
title:"car",
price: 12
}]
}) {
product {
id
}
}
}
Share
Improve this question
edited Jun 6, 2020 at 15:40
Taha Farooqui
asked Jun 6, 2020 at 15:31
Taha FarooquiTaha Farooqui
7571 gold badge11 silver badges27 bronze badges
3
- 1 why do you need double quotes? – Richard Commented Jun 6, 2020 at 15:33
- 1 @Richard I want to use in graphql query, The query only accepts value with double quotes . – Taha Farooqui Commented Jun 6, 2020 at 15:35
- 2 that’s not valid json and should be fixed upstream if possible. json requires double quotes around the keys and the string values. where are you getting it? – ray Commented Jun 6, 2020 at 15:35
3 Answers
Reset to default 2I don't see, any problem using JSON.stringify
you can either get the string directly and use it inside a query or if you need a javascript object, you can just parse it.
JSON.Stringify
JSON.parse
Passing arguments in GraphQl
const unwantedResponse = [{
title: 'Car',
price: 2323,
}]
const wantedResponse = JSON.stringify(unwantedResponse);
const parsedResponse = JSON.parse(wantedResponse)
console.log(wantedResponse);
console.log(parsedResponse);
You can use JSON.parse() method parses a JSON string and The JSON.stringify() method converts a JavaScript object or value to a JSON string.
let obj =[
{
title: 'Car',
price: 2323,
}
];
let result = JSON.parse(JSON.stringify(obj));
console.log(result);
the result is
[
{
title: "Car",
price: 2323,
}
]
You could apply: JSON.stringify
(which converts a JS object to a JSON string), then JSON.parse
(which parses a JSON string back to a JS object), e.g.
let x = [{
title: 'Car',
price: 2323,
}];
x = JSON.parse(JSON.stringify(x));
console.log(x);
本文标签: javascriptreplace JSON object value single quote with double quoteStack Overflow
版权声明:本文标题:javascript - replace JSON object value single quote with double quote - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745274515a2651098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论