Looking for an easier way to generate an element with nested attributes using the json generator. How would you generate the 'parent' element?enter image description here

  • What you want to achieve here? Is it something which will be returned by jsRemoting? If you want to do that then you can create wrapper classes in apex and return custom type from remoting method. – Kiran Machhewar Dec 8 '15 at 18:15

Your parent attribute on the outer object just needs to represent an instance of another object (class).

Class Structure

public class Container {
    public ParentItem parent { get; set; }

public class ParentItem {
    public String link { get; set; }
    public String value { get; set; }


Container c = new Container();

c.parent = new ParentItem();
c.parent.link = 'yourURL';
c.parent.value = 'yourValue';

String cAsJSON = JSON.serialize(c);

  • Much appreciated. – humanoid Dec 8 '15 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.