1

How do I rename Object name from Cars to automobiles? I tried using ObjectRenameKeys but it works on the properties within objects not the object name itself.

Original:

"Cars": [
                {

                    "Part": 1
                },
                {

                    "Part": 2
                },
                {

                    "Part": 3
                }
            ],
Expected: 

"Automobiles": [
                {

                    "Part": 1
                },
                {

                    "Part": 2
                },
                {

                    "Part": 3
                }
            ],
2
  • You seem to have properties inside objects ... otherwise these are syntax errors. Also what do you mean with ObjectRenameKeys ? Commented Jul 22, 2019 at 22:36
  • For your reference-npmjs.com/package/object-rename-keys Commented Jul 22, 2019 at 22:41

1 Answer 1

3

You can't really rename properties....just copy Cars and then delete it:

myObject.Automobiles = myObject.Cars;
delete myObject.Cars;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.