有没有办法格式化 json Rest api,使其不被缩小。我正在使用 NodeJs/lambda 和 AWS API 网关。我想要的是:
由此:
{"name":"Ultimate data","description":"This is an example api build for get requests","number":"40"}
为此:
{
"name":"Ultimate data",
"description":"This is an example api build for get requests",
"number":"40"
}
我的nodejs代码
exports.handler = async (event) => {
if (event.httpMethod === 'GET') {
return getData(event);
}
};
const getData = event => {
let data = {
name: 'Ultimate data',
description: 'This is an example api build for get requests',
number: '40'
};
return {
statusCode: 200,
body: JSON.stringify(data)
};
};
API 网关/Lambda 中是否有一个选项?
最佳答案
我想 JSON.stringify(data, null, 2)
应该可以。 2 基本上是缩进空间。
关于javascript - 使用nodejs和Lamda正确设置rest api格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60547329/