Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7560997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:03:09+00:00 2026-05-30T13:03:09+00:00

I’d like to validate json contains a list of key/values before attempting to marshall

  • 0

I’d like to validate json contains a list of key/values before attempting to marshall into a case class using lift-json. The data might be nested.

For example:

{ 
 "name": "stack",
 "desc": "desc",
 "age": 29,
 "address": {
  "street": "123 elm", 
  "postal_code": 22222,
  "city": "slc",
 }
}

What are ways I can verify this JSON contains values for “name”, “age”, and “address\street”? Assume all other fields are optional.

Sorry if I’m missing something obvious, but I suspect something like this has been solved before.

By the way, anyone try Orderly? https://github.com/nparry/orderly4jvm

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:03:10+00:00Added an answer on May 30, 2026 at 1:03 pm

    As I see it you’ve got a few options:

    1. You could use lift-json’s “Low level pull parser API” (search for that phrase on this page) to grab each of the fields you care about. If you haven’t gotten all of the fields you want at the point that you encounter the End token, you toss an exception. If you have of the required field, then create your object.

      Pro: This only parses the JSON once. It’s the highest performing way of using lift-json.

      Con: You’ve created brittle, hand rolled software.

    2. You could use lift-json’s JsonAST, which is the normal result of calling its parse method (search for “Parsing JSON” on this page), and then its XPath-like expressions (search for “XPath + HOFs” on this page) to determine if the required fields are present. If they are, create your object by passing the appropriate fields to the constructor.

      Pro: Less hand rolled than #1. Only parses the data one time.

      Con: This isn’t quite as fast as #2.

    3. Use the methods from #1 or #2 to determine if the required fields are present. If they are, then use lift-json’s deserialization (look for the “Serialization” heading on this page) to create and object.

      Pro: I’m really stretching here… If you expected much of the data to be bad, you’d be able to determine that before entering the somewhat more heavyweight process of lift-json deserialization

      Con: You’ve parsed the data twice in the case that the data is valid.

    4. Just use lift-json’s deserialization (look for the “Serialization” heading on this page). It more or less does what is described in #2, except it uses reflection to figure out which fields are required.

      Pro: This is the most maintainable solution

      Con: It’s slower than #1 and #2.

    My recommendation: Unless you absolutely need the best possible performance, use #4. If you really have a need for speed, use #1. One other benefit of using a #1 or a #2 style solution is that they allow you to do odd coercion to the data, such as mapping two alternative field names in JSON to a single field in the scala object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.