Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orDefault function #355

Merged
merged 9 commits into from
Oct 18, 2023
Merged

orDefault function #355

merged 9 commits into from
Oct 18, 2023

Conversation

TomWright
Copy link
Owner

Add a new function orDefault.

It takes 2 arguments:

  • A selector string
  • A selector string that will be used as a fallback

The first selector is expected to return a single value.
The second selector is used if the first causes a NotFound error and is expected to always return a single value.

Example usage:

$ echo '{
  "-LCr5pXw_fN32IqNDr4E": {
    "bookCategory": "poetry",
    "locale": "en-us",
    "mediaType": "book",
    "publisher": "Pomelo Books",
    "title": "Sound Waves",
    "type": "poetry"
  },
  "-LDDHjkdY0306fZdvhEQ": {
    "ISBN13": "978-1534402966",
    "bookCategory": "fiction",
    "title": "What Can You Do with a Toolbox?",
    "type": "picturebook"
  }
}' | dasel -r json 'all().mapOf(projectId,key(),title,title,bookCategory,bookCategory,type,type,locale,orDefault(locale,string(unknown)))'
{
  "bookCategory": "poetry",
  "locale": "en-us",
  "projectId": "-LCr5pXw_fN32IqNDr4E",
  "title": "Sound Waves",
  "type": "poetry"
}
{
  "bookCategory": "fiction",
  "locale": "unknown",
  "projectId": "-LDDHjkdY0306fZdvhEQ",
  "title": "What Can You Do with a Toolbox?",
  "type": "picturebook"
}

@TomWright TomWright merged commit 150ec34 into master Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant