Created
June 8, 2021 17:28
-
-
Save Anthonyhawkins/f6350db346186b2cd551a5b5a1b108b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import json | |
import _jsonnet | |
jsonnet_str = ''' | |
{ | |
person1: { | |
name: "Alice", | |
welcome: "Hello " + self.name + "!", | |
}, | |
person2: self.person1 { | |
name: std.extVar("OTHER_NAME"), | |
}, | |
} | |
''' | |
json_str = _jsonnet.evaluate_snippet( | |
"snippet", jsonnet_str, | |
ext_vars={'OTHER_NAME': 'Bob'}) | |
json_obj = json.loads(json_str) | |
for person_id, person in json_obj.iteritems(): | |
print '%s is %s, greeted by "%s"' % ( | |
person_id, | |
person['name'], | |
person['welcome']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment