9.6 Converting .json pipe files to .yaml - NEONScience/NEON-IS-data-processing GitHub Wiki

Conversion is super easy, and the earlier you start, the more time you'll save down the road.

Do it Online

For a non-automated process, go to https://www.json2yaml.com/

Paste in the .json text you wish to convert.

Out pops the yaml format. When pasting the yaml format back into your text editor, make sure you pay attention to the appropriate indentations.

A big convenience to yaml is that you may add notes simply by beginning a comment with #.

Once saved, you may then stand up your pipeline using a *.yaml file instead of a *.json.

Do it in R

library(magrittr)

#Point to your pipeline spec files directory 
specPath = "~/GitHub/NEON-IS-data-processing/pipe/parQuantumLine/"

# discover our Json files
inputFiles=dir(path = specPath, pattern = ".json$", full.names = TRUE)

# make new file names to use
outputFiles=gsub(pattern = ".json$", replacement = ".yaml", x = inputFiles)

# loop thru our files, performing the conversion and writing the files out.
for(i in 1:length(inputFiles)){
  
  jsonlite::read_json(inputFiles[i]) %>%
  yaml::as.yaml() %>%
    gsub(pattern = "yes", replacement = "true") %>%
    gsub(pattern = "no", replacement = "false") %>%
    c("---",.) %>%
    writeLines(con =  outputFiles[i])
  
  
}

# there should now be working yaml files to use in the directory you specified above