Avatar of Dinesh Kumar
Dinesh Kumar
Flag for India asked on

JSON Keys to be converted to lowercase programmatically.

In the following angularjs code, $scope.productsNew contains json array whose keys are not in lowercase, they are like  Id, Sku, Description I need them to be like id, sku,description

I need to change them to lowercase in angularjs, could you help me in this.

function storeController($scope,$http) {

    function onUserComplete(response) {        
        $scope.productsNew = [{ Id: 3, Sku: 'APL', Name: 'Apple', Description: 'Eat one every day to keep the doctor away!', Price: 20 }, 
              { Id: 4, Sku: 'BAN', Name: 'Banana', Description: 'These are rich in Potassium and easy to peel.', Price: 40 }];
    };
    
    function onError(reason) {
        $scope.error = "Could not fetch the Products";
    };

    $http.get("http://localhost:60128/Products-Service/Products")
    .then(onUserComplete, onError);

}

Open in new window


Thanks
meetDinesh
JavaScriptC#jQuery

Avatar of undefined
Last Comment
Dinesh Kumar

8/22/2022 - Mon
ste5an

I would guess, they are that way for a good reason. Using your own modified keys may later collide when your objects may contain both keys in different cases.

Otherwise, I'm using _.map() in such cases.
Dinesh Kumar

ASKER
If you can provide _.map()  example that fits good in my scenario
ASKER CERTIFIED SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dinesh Kumar

ASKER
Adding underscore.js will put extra burden on site as I am using angularjs

dont' you think!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Michel Plungjan

Especially since map and reduce already exist in JavaScript
ste5an

Well, it's the concept, isn't it? Not the tool, which matters. As I said I'm using _,cause I'm used to it.
Dinesh Kumar

ASKER
Thank  you.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.