Convert returned JSON Object Properties to (lower first) camelCase

后端 未结 18 2301
忘掉有多难
忘掉有多难 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:35

    Here's handy library you might wanna try: https://www.npmjs.com/package/camelize2

    You simply need to install it with npm install --save camelize2 and then

    const camelize = require('camelize2')
    
    const response = {
       Contacts: [{ GivenName: "Matt", FamilyName:"Berry" }]
    }
    
    const camelizedResponse = camelize(response)
    

提交回复
热议问题