Giter Site home page Giter Site logo

etl_script's Introduction

ETL Bash Script Image

Summary

This Extract, Transform, Load script takes a JSON file as input and outputs a JSON file. It is for use with an ETL software that dynamically builds JSON requests to other systems.

Demo

ETL Gif

View an 8 minute demo on Vimeo here.

Here is how it works:

  1. Provide a sample JSON request
  • This request body is in the structure that the destination system is expecting its request from the ETL software
  • The JSON file resulting from this script will "teach" the ETL software how to build JSON like the request body. It is ultimately loaded into the ETL software (a process separate from this script).
  1. Answer whether you'd like to preserve the JSON order
  • While JSON is unordered, the ETL software displays the mappings in the order they were input. It can be more readable for users of the ETL software for mappings to match the order of the JSON keys.
  1. Obtain resulting JSON file
  • Again, this is loaded into the ETL software via a process outside this script.

I wrote this script to automate a previously manual process that required careful review of sometimes complex JSON bodies.

It asks for an endpoint URL at one point, at which point the user should enter the requested value.

This is a lengthy BASH script, at the 350-line mark. If I could do this over I may consider using Python instead.

Getting Started

System Requirements

The script relies on several command line tools for managing JSON:

  • jq, for general JSON processing
  • jo, for generating JSON objects
  • gron, for transforming JSON into clear paths

You can install all tools at once via Homebrew with this command:

$ brew install jq jo gron

Usage

To grant executable permission to the script, run this command:

$ chmod u+x generate_mappings.sh

Run the script:

$ ./generate_mappings.sh

Notes

  • Ensure you have placed a single .json file in the directory at the root level named parse/
  • An error will be thrown if the input file contains invalid JSON

Known Issues

  • JSON bodies with keys that contain a - character will be escaped in the generated JSON, causing problems for loading into the ETL software

FAQ

Q: Why doesn't my JSON delivery look perfectly identical to my example JSON request body?

A: JSON is "an unordered set of name/value pairs". After reviewing jq, catj, gron, and other tools that find all paths in a JSON object, none consistently preserved the location of each key-value pair unfortunately.

gron gets the closest, however. And so when the select menu asks you if you want to preserve the location of your key-value pairs, you can execute gron in a way that attempts to preserve the location. The method is not very high tech and so if it tries and fails after a couple seconds, ^C out of the script and decline location preservation next time.

etl_script's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.