【发布时间】:2022-09-22 22:16:19
【问题描述】:
我有一个带有camelCase键的对象
{
\"studentName\": \"ABC\",
\"studentId\": \"12345\",
\"age\": 18,
\"submittedAt\": \"xxxxxx\"
}
我想将上面的对象转换为键snake_case
{
\"student_name\": \"ABC\",
\"student_id\": \"12345\",
\"age\": 18,
\"submitted_at\": \"xxxxxx\"
}
我有一个从camelCase转换为snakeCase的功能
const camelToSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
但是,我对如何在 JSON 对象中转换键感到很困惑。任何建议表示赞赏。
-
(当然在建议的副本中应用您自己的转换代替
toLowerCase())
标签: javascript json typescript ramda.js