Convert returned JSON Object Properties to (lower first) camelCase

后端 未结 18 2323
忘掉有多难
忘掉有多难 2020-12-04 21:05

I have JSON returned from an API like so:

Contacts: [{ GivenName: "Matt", FamilyName: "Berry" }]

To keep this consistent

18条回答
  •  臣服心动
    2020-12-04 21:25

    If you would use lodash instead of underscore, this would do:

    _.mapKeys(obj, (v, k) => _.camelCase(k))
    

    This would convert both TitleCase and snake_case to camelCase. Note that it is not recursive though.

提交回复
热议问题