Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to convert Live Contract scenario Yaml to JSON
<?php
$file = $argv[1];
$tagToStruct = function($value, $tag) {
$key = substr($tag, 1);
return ["<$key>" => $value];
};
$callbacks = [
'!if' => $tagToStruct,
'!ref' => $tagToStruct,
'!eval' => $tagToStruct,
'!ifset' => $tagToStruct,
'!switch' => $tagToStruct,
'!merge' => $tagToStruct,
'!tpl' => $tagToStruct,
'!apply' => $tagToStruct,
'!dateFormat' => $tagToStruct,
'!id' => $tagToStruct,
];
$scenario = yaml_parse_file($file, 0, $ndocs, $callbacks);
echo json_encode($scenario, JSON_PRETTY_PRINT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment