{"id":16481204,"url":"https://github.com/dfinke/psyamlquery","last_synced_at":"2025-03-23T11:33:10.667Z","repository":{"id":66743361,"uuid":"282653547","full_name":"dfinke/PSYamlQuery","owner":"dfinke","description":"PowerShell wrapper for `yq`, enables a better PowerShell pipeline experience","archived":false,"fork":false,"pushed_at":"2020-08-27T21:36:05.000Z","size":3467,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T20:13:14.567Z","etag":null,"topics":["powershell","yaml","yq"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dfinke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-07-26T13:16:31.000Z","updated_at":"2025-01-23T21:16:10.000Z","dependencies_parsed_at":"2023-04-18T17:30:37.949Z","dependency_job_id":null,"html_url":"https://github.com/dfinke/PSYamlQuery","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinke%2FPSYamlQuery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinke%2FPSYamlQuery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinke%2FPSYamlQuery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinke%2FPSYamlQuery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfinke","download_url":"https://codeload.github.com/dfinke/PSYamlQuery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245097167,"owners_count":20560311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["powershell","yaml","yq"],"created_at":"2024-10-11T13:06:43.874Z","updated_at":"2025-03-23T11:33:08.885Z","avatar_url":"https://github.com/dfinke.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cp style=\"text-align:center;\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/dfinke/PSYamlQuery/master/media/food.jpg\" width=275/\u003e\u003c/p\u003e\n\n## PS Yaml Query\n\nPowerShell wrapper for `yq`, enables a better PowerShell pipeline experience.\n\n[yq](https://github.com/mikefarah/yq) - a lightweight and portable command-line YAML processor, whose aim is to be the [jq](https://github.com/stedolan/jq) or `sed` of yaml files.\n\n- GitHub - https://github.com/mikefarah/yq\n- GitBook - https://mikefarah.gitbook.io/yq/\n\n## Note\n\n\u003e Not all of the `yq` features are wrapped in PowerShell yet.\n\n# Install\n\n`yq` needs to be installed. You can install it using: `choco install yq`.\n\nOr, check here for other install options: https://mikefarah.gitbook.io/yq/#install\n\n# Try it Out\n## Import-Yaml\n\n`docker-compose.yml`\n\n```yaml\nversion: '3'\nservices:\n    powershellmicroservice:\n        build: .\\powershell\n        ports:\n            - 8080:8080\n    pythonmicroservice:\n        build: .\\python\n        ports:\n            - 8081:8081\n    denomicroservice:\n        build: .\\deno\n        ports:\n            - 8082:8082\n    dotnetcoremicroservice:\n        build: .\\dotnetcore\n        ports:\n            - 3000:80\n```\n\nDo the `Import-Yaml`, and print the `services` property.\n\n```powershell\n$r = Import-Yaml docker-compose.yml\n\n$r.services\n```\n\n### Results \n\n```\ndenomicroservice       : @{build=.\\deno; ports=System.Object[]}\ndotnetcoremicroservice : @{build=.\\dotnetcore; ports=System.Object[]}\npowershellmicroservice : @{build=.\\powershell; ports=System.Object[]}\npythonmicroservice     : @{build=.\\python; ports=System.Object[]}\n```\n\n## Path Expression \n\n`yq` also supports a path expression and returns the matching nodes the given yaml file.\n\nUsing the `docker-compose.yml` example above, and the path expression `services.dotnetcoremicroservice`.\n\n```powershell\nImport-Yaml docker-compose.yml services.dotnetcoremicroservice\n```\n\n## Then\n\n```\nbuild        ports\n-----        -----\n.\\dotnetcore {3000:80}\n```\n\nThis is equivalent to to `(Import-Yaml .\\sample-docker-compose.yml).services.dotnetcoremicroservice` in PowerShell, but the PoweShell approach is more typing.\n\n## ConvertTo-Yaml\n\n```powershell\nConvertTo-Yaml '{\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}}' \n```\n\n- Or \n\n```powershell\n'{\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}}' | ConvertTo-Yaml \n```\n\n\n### Results \n\n```\na: Easy! as one two three\nb:\n  c: 2\n  d:\n    - 3\n    - 4\n```\n\n## Compare-Yaml\n\nDeeply compare two yaml documents.\n\nCompares the matching yaml nodes at path expression in the two yaml documents. See path expression for more details. Difference calculated line by line, and is printed out line by line where the first character of each line is either:\n\n- a `space`, indicating no change at this line\n- `-` a minus ,indicating the line is not present in the second document (it's removed)\n- `+` a plus, indicating that the line is not present in the first document (it's added)\nIf there are differences then yq will print out the differences and exit with code 1. If there are no differences, then nothing will be printed and the exit code will be 0.\n\n`animal.yml`\n\n```yaml\nanimals:\n    - cats\n    - dog\n    - cheetah\n```\n\n`different-animals.yml`\n\n```yaml\nanimals:\n    - cats\n    - bird\n    - cheetah\n```\n\nDo the comparison.\n\n```powershell\nCompare-Yaml animal.yml different-animals.yml\n```\n\n### Result\n\n- `cats` and `cheetah` no change\n- `dog` not present in the second file\n- `bird` not present in the first file, and was added\n\n```\n animals:\n   - cats\n-  - dog\n+  - bird\n   - cheetah\n```\n\n## Merge-Yaml\n\nMerge multiple yaml files into a one.\n\nYaml files can be merged using the 'merge' command. Each additional file merged with the first file will set values for any key not existing already or where the key has no value.\n\n`data1.yml`\n\n```yaml\na: simple\nb: [1, 2]\n```\n\n`data2.yml`\n\n```yaml\na: other\nc:\n  test: 1\n```\n\n```powershell\nMerge-Yaml data1.yaml data2.yaml\n```\n\n### Result\n\n```\na: simple\nb: [1, 2]\nc:\n  test: 1\n```\n\n## Merge-Yaml : Append values with arrays\n\n`data1.yml`\n\n```yaml\na: simple\nb: [1, 2]\nd: hi\n```\n\n`data2.yml`\n\n```yaml\na: something\nb: [3, 4]\nc:\n  test: 2\n  other: true\n```\n\n```powershell\nMerge-Yaml data1Append.yml data2Append.yml -Append\n```\n\n### Results\n\n```\na: simple\nb: [1, 2, 3, 4]\nd: hi\nc:\n  test: 2\n  other: true\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfinke%2Fpsyamlquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfinke%2Fpsyamlquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfinke%2Fpsyamlquery/lists"}