Menu

JSONPath Cheat Sheet: Querying Nested JSON Without Lodash
πŸ“°

JSONPath Cheat Sheet: Querying Nested JSON Without Lodash

DEV CommunityΒ·Ashish KumarΒ·7 months ago
#WfCpHqAf
#json#javascript#webdev#books#jsonpath
Reading 0:00
15s threshold

You've got a 200-line JSON response. You need the email of every user whose lastLogin is older than 30 days, but only from the team department, sorted by id . You start writing a .filter().map() chain and twenty minutes later you're debugging an undefined because one user's meta object is missing.

This is what JSONPath was built for. It's a query language for JSON, the way XPath is for XML. You can write $.users[?(@.lastLogin < @.threshold)].email and skip the imperative gymnastics.

This is the cheat sheet I keep open while writing API tests, debugging GraphQL responses, and combing through CloudWatch logs.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.