github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0165.yml (about) 1 doc_meta: | 2 folder: template 3 title: yml obj json conversion 4 head: | 5 demo how to mutually convert yml, json, object between each other 6 7 sections: 8 - title: How does it work 9 content: | 10 ``` 11 yml --ymlToObj--> obj --objToYml--> yml 12 yml --ymlToObj--> obj --toJson--> json 13 ``` 14 15 - title: Relavant 16 content: environment variables 17 refs: 18 - title: parse yml to object 19 link: ../../object-oriented/c0074/ 20 21 vars: 22 yml: | 23 address: 24 suburb: 25 name: sydney CBD 26 postcode: 2000 27 school: SG 28 obj: 29 address: 30 suburb: 31 name: sydney CBD 32 postcode: 2000 33 school: SG 34 35 tasks: 36 - 37 name: task 38 task: 39 - 40 func: cmd 41 dvars: 42 - name: void 43 desc: convert yml string to obj 44 value: '{{.yml | ymlToObj|reg "this_is_an_obj"}}' 45 do: 46 - name: print 47 cmd: '{{.yml}}' 48 - name: print 49 desc: print string representation of obj 50 cmd: '{{.yml | ymlToObj}}' 51 - name: printObj 52 desc: print object 53 cmd: this_is_an_obj 54 - name: print 55 desc: object to json text 56 cmd: '{{ .obj | toJson}}' 57 - name: print 58 desc: convert yml string to obj in print 59 cmd: '{{.yml | ymlToObj|reg "this_is_another_obj"}}' 60 - name: print 61 desc: print this_is_another_obj 62 cmd: '{{.this_is_another_obj}}' 63 - name: print 64 desc: | 65 object to json text then to obj using ymlToObj 66 yml is a superset of json, so ymlToObj works for json 67 cmd: '{{ .obj | toJson |ymlToObj}}' 68 - name: print 69 desc: | 70 object to json text 71 then to obj using ymlToObj 72 then to yml 73 cmd: '{{ .obj | toJson |ymlToObj|objToYml}}'