0

hello i have a response in json that looks like that

{
    "el": {
        "reviewed_percentage": "0%",
        "completed": "16%",
        "untranslated_words": 8,
        "last_commiter": "zaabalonso",
        "reviewed": 0,
        "translated_entities": 1,
        "translated_words": 1,
        "last_update": "2012-07-06 13:08:10",
        "untranslated_entities": 5
    },
    "en": {
        "reviewed_percentage": "0%",
        "completed": "100%",
        "untranslated_words": 0,
        "last_commiter": "zaabalonso",
        "reviewed": 0,
        "translated_entities": 6,
        "translated_words": 9,
        "last_update": "2012-07-06 12:28:48",
        "untranslated_entities": 0
    },
    "gl_ES": {
        "reviewed_percentage": "0%",
        "completed": "33%",
        "untranslated_words": 7,
        "last_commiter": "zaabalonso",
        "reviewed": 0,
        "translated_entities": 2,
        "translated_words": 2,
        "last_update": "2012-07-06 13:06:46",
        "untranslated_entities": 4
    }
}

how can i convert it like that using javascript

[{
            "language"="el",
            "reviewed_percentage": "0%",
            "completed": "16%",
            "untranslated_words": 8,
            "last_commiter": "zaabalonso",
            "reviewed": 0,
            "translated_entities": 1,
            "translated_words": 1,
            "last_update": "2012-07-06 13:08:10",
            "untranslated_entities": 5},
........etc.
]
2
  • 1
    JSON is just a javascript data structure in text format. Conver it to native JS data, then treat it like you would any other array/object. Commented Jul 14, 2012 at 16:11
  • ok i'll make it an object and then how am i going to access elements object["el"].completed? Commented Jul 14, 2012 at 16:13

1 Answer 1

1

You can loop through the JSON data and create a new set of data with the format you desire, such as using the pseudo code below (assuming oldJSON is assigned as the JSON response as posted)

var newData = [];
for ( var s in oldJSON )
{
    var data = oldJSON[s];
    data.language = s;
    newData.push(data);
}
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.