Last active
October 3, 2020 23:31
-
-
Save jtigger/4a26bf1b0a629a74d1c7f2ee42ad57ac to your computer and use it in GitHub Desktop.
Parse empty node in YAML (many languages)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var yamlParser = require("yaml-parser") | |
yamlParser.safeLoadAll("---\nfoo: #@ data.value\n", (doc) => { console.log(doc); }); | |
// https://runkit.com/embed/oipcfk86vcq2 | |
// output: | |
// Object{foo:null} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
puts YAML.load("---\nfoo: #@ data.value\n") | |
# output: | |
# {"foo"=>nil} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate yaml_rust; | |
use yaml_rust::{YamlLoader}; | |
fn main() { | |
let s = | |
"--- | |
foo: #@ data.value | |
"; | |
let docs = YamlLoader::load_from_str(s).unwrap(); | |
let doc = &docs[0]; | |
println!("{:?}", doc); | |
} | |
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=50b2343706643e84cb4114f9add6189c | |
// output: | |
// Hash({String("foo"): Null}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// on classpath: https://repo1.maven.org/maven2/org/yaml/snakeyaml/1.27/snakeyaml-1.27.jar | |
package emptynode; | |
import org.yaml.snakeyaml.Yaml; | |
import java.util.Map; | |
public class ParseYaml { | |
public static void main(String[] args) { | |
Yaml yaml = new Yaml(); | |
Map<String, Object> obj = yaml.load("---\nfoo: #@ data.value\n"); | |
System.out.println(obj); | |
} | |
} | |
// output: | |
// {foo=null} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment