Skip to content

Instantly share code, notes, and snippets.

@jasny
Created June 13, 2019 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasny/78bbbbb075be8bb1263b3c44b738ad89 to your computer and use it in GitHub Desktop.
Save jasny/78bbbbb075be8bb1263b3c44b738ad89 to your computer and use it in GitHub Desktop.
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