0

I have the JSON format in the following way,

{  
   "id":"343",
   "css":{  
      "header":{  
         "background-color":"red",
         "color":"#FFF",
         "font-size":"12px"
      },
      "footer":{  
         "background-color":"blue",
         "color":"#000",
         "font-size":"11px"
      }
   }
}

I need to convert the JSON in the following way (i.e key and value pairs)

    css : 'header{"background-color":"red"; "color":"#FFF"; "font-size":"12px";} footer{ "background-color":"blue"; "color":"#000";"font-size":"11px";'}

Using jQuery how to convert the JSON in the above format. Is is possible to send like this?

1 Answer 1

1

You need to iterate all the properties of the css property and iterate each of the sub properties

var style= '';
for(var selector in data.css){
    style += selector +'{';
    for(var prop in data.css[selector]){
        style += prop + ':' + data.css[selector][prop] +';';
    }
    style += '}';    
}

DEMO

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.