Jennifer Lopez has asked Supreme Court Justice Ruth Bader Ginsburg for marriage advice.

The 'On the Floor' hitmaker is set to tie the knot with her partner Alex Rodriguez in the near future after he popped the question in the Bahamas in March but, following three failed marriages, the brunette wants to make sure she gets it right this time and has been asking the 86-year-old lawyer, who was married for over 50 years, for the secret to a ''happy'' relationship.

Speaking at the Library of Congress's National Book Festival in Washington, D.C. this weekend, Ruth said: ''I was called up about a month or so ago by Jennifer Lopez, and she said she would like to meet me and introduce her fiancé Alex Rodriguez. So they came to chambers, and we had a very nice visit. She mostly wanted to ask if I had any secret about a happy marriage. But now ARod is traveling with her to concerts all over the world...''

The interviewer at the panel discussion asked: ''So what was your secret to a happy marriage?''

To which Ruth said: ''Yeah, on the day I was married, my mother in law took me aside and said she wanted to tell me what was the secret of a happy marriage. And I said I'd be glad to hear what is it, and she responded it helps sometimes to be a little deaf.''

The 50-year-old singer later shared the snippet from the panel talk on her Instagram account and captioned it: ''It was an honor to meet RBG... I so look up to her as a person, a woman, and a human being; but also as a wife, a working woman, and a passionate advocate for equality for women and minorities, the underprivileged of this country.

''I was in awe of her, watching how powerful and sharp she is, how clear and full of wisdom... I loved her advice for a happy marriage, but my favorite response of hers was to a question I asked about the country seeming so broken right now and divided, and that it's sad to me, and what should Alex and I be doing... how can we help? And she said, ''Keep doing what you're doing, inspiring people and living by example. You must continue to change the world with your respective gifts.'' I thought to myself yes, be your best self, put love into the world and justice, not hate and fear; help wherever and whenever you can. And following that piece of sage advice... that's what we intend to do.#thenotoriousRGB #weretakingthemarriageadvicetoo (sic)''

Jennifer was previously married to Ojani Noa, Cris Judd and Marc Anthony.

She has 11-year-old twins Max and Emme with Marc, while Alex, 44, has daughters Natasha, 14, and Ella, 11, with his ex-wife Cynthia Scurtis.