jborean93 / PowerShell-Yayaml

A YAML parser and writer that uses an Assembly Load Context on PowerShell 7+
MIT License
30 stars 2 forks source link

Feature Request: ConvertFrom-Yaml -AsJSON #20

Closed JustinGrote closed 1 month ago

JustinGrote commented 1 month ago

To avoid any eccentricities with PowerShell ETS, etc. in converting from YAML to JSON, provide a -AsJSON that can serialize the YamlObject once read into JSON and output as a string.

https://dotnetfiddle.net/TntEwC

jborean93 commented 1 month ago

Have you tried using the YAML 1.2 JSON schema which is meant to be JSON friendly?

@{foo='bar';test=@(1, 2, 'three')} | ConvertTo-Yaml -Schema Yaml12JSON
# {"foo": "bar", "test": [1, 2, "three"]}
JustinGrote commented 1 month ago

No I was not aware that was a thing! Seems to have worked at least for my use case, thanks!

jborean93 commented 1 month ago

There are a few builtin schemas, I've tried to document them under https://github.com/jborean93/PowerShell-Yayaml/blob/main/docs/en-US/about_YamlEmitting.md#schemas. Let me know if there is anything emitted by that schema that isn't valid JSON and I can look into it further.