FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
maxm

maxm

diesel

Remix of yawnxyz/diesel
Public
Like
diesel
Home
Code
2
README.md
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
11/26/2024
README.md

Diesel

Diesel is a lightweight data manipulation library inspired by Tom Wright's Dasel, designed for easy querying and transformation of various data formats such as JSON, YAML, CSV, and TOML. It allows users to select, update, and delete data using a simple selector syntax.

Heavily adapted from https://github.com/TomWright/dasel

Features

  • Multi-format Support: Works with JSON, YAML, CSV, and TOML.
  • Dynamic Selectors: Use conditions to filter data dynamically.
  • Function Support: Built-in functions for data manipulation (e.g., length, sum, avg).
  • Easy Integration: Can be used in both Deno and Val Town environments.

Usage

import Diesel from "https://esm.town/v/yawnxyz/diesel";

async function main() {
  const jsonData = `
  {
    "users": [
      {"id": 1, "name": "Alice", "age": 30},
      {"id": 2, "name": "Bob", "age": 25},
      {"id": 3, "name": "Charlie", "age": 35}
    ],
    "settings": {
      "theme": "dark",
      "notifications": true
    }
  }
  `;****

  const diesel = new Diesel(jsonData, 'json');
  try {
    console.log("All data:", await diesel.select(''));
    console.log("All users:", await diesel.select('users'));
    console.log("First user's name:", await diesel.select('users.[0].name'));
    console.log("Users over 30:", await diesel.select('users.(age>30)'));
    
    await diesel.put('settings.theme', 'light');
    console.log("Updated settings:", await diesel.select('settings'));
    
    // await diesel.delete('users.[1]');
    // console.log("Users after deletion:", await diesel.select('users'));
    
    console.log("Data in YAML format:");
    console.log(await diesel.convert('yaml'));
    
    console.log("Data in TOML format:");
    console.log(await diesel.convert('toml'));
    
    console.log("Number of users:", await diesel.select('users.length()'));
    console.log("User names in uppercase:", await diesel.select('users.[*].name.toUpper()'));
  } catch (error) {
    console.error("An error occurred:", error);
  }
}

main();

Installation

To use Diesel, simply import it in your Deno project as shown in the usage example.

License

This project is licensed under the MIT License.

FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareersBrandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.