What is DTL?
DTL allows you to describe how to transform one set of data into another. DTL can be used within your backend or frontend code to transform your data between formats, validate input data, or perform complex calculations. It can also be used to reliably manipulate huge amounts of data both in batch processing and in realtime scenarios.
In short, DTL is useful whenever you need to generate a new piece of data using data you already have.
DTL is great for handling input data from forms or API calls, it's fantastic for converting between data formats, and is tailor-made for transforming your data to and from formats used by the APIs you use.
Also, if you are into that whole ETL thing, DTL is amazing.
The dtl command line tool is like having all the *nix text tools (like grep, awk, sed, cut etc.) for your complex data structures, and works with JSON, yaml, and csv data.
Finally, the dtlr REPL tool has built-in help and is great for trying things out on the command line.
Try it out!
You can try DTL below. Select an example to auto-fill with sample data and related DTL transform, then click the button to apply the DTL transform. Your result will be displayed in the Result box. (Pro tip: Try editing the transform or input data to change the result.)
Load an example:
How do I get DTL?
Installing DTL is easy...
To use DTL in your site or browser-based app, simply use the dtl-transform-browser.min.js from the npm package, or include it from the jsdelivr.net CDN:
To use DTL to experiment, you can load the dtlr REPL environment by issuing the following command:
Once the REPL environment is loaded, you can enter the command .help to get general help, or .help followed by the name of a helper function to get help on that function, for example:.help grep will show you the documentation for the grep function.
How do I use it in my code?
To use DTL in your code, simply require the DTL module in your code:
You can browse the DTL npm page for a longer example.
How do I use the dtl CLI tool
The dtl command line tool allows you to apply complex (or simple) DTL transforms to data on the command line without writing any code. It understands JSON, JSONLines, YAML and CSV data for both input and output. Issue the command below for help:
To convert data from yaml to JSON:
To convert data from JSON to yaml:
Take JSON input on stdin, and output YAML on stdout
To extract names from a list of people
More DTL docs
DTL has extensive documentation on its syntax and helpers. You can find information on the expression syntax here and information about the helper functions within DTL in the helper reference. Some docs on some more advanced topics exists. You can also try out dtl and get help in the dtlr command line tool.
Talk to us!
If you would like to chat about DTL and related topics, you can find us on Discord here.