I have a json data like this.
sample.json
[
{
"id": 0,
"name": "Cofine",
"title": "laboris minim qui nisi esse amet non",
"description": "Consequat laborum quis exercitation culpa. Culpa esse sint consectetur deserunt non.",
"website": "cofine.com",
"image": "http://placehold.it/32x32",
"labels": ["blue", "red"],
"labels_link": ["http://cofine.com/labels/blue","http://cofine.com/labels/red"],
},
{
"id": 1,
"name": "Zomboid",
"title": "adipisicing mollit esse aliquip ullamco nisi laboris",
"description": "Enim consectetur eu commodo officia. Id pariatur proident nostrud occaecat adipisicing voluptate do nisi incididunt id ex commodo.",
"website": "zomboid.com",
"image": "http://placehold.it/32x32",
"labels": ["red"],
"labels_link": ["http://zomboid.com/labels/red"],
},
{
"id": 2,
"name": "Sulfax",
"title": "non minim anim irure nulla ad elit",
"description": "Pariatur anim officia adipisicing Lorem dolor cillum eu ex veniam sint consequat incididunt. Minim mollit reprehenderit mollit sint laboris consequat.",
"website": "sulfax.com",
"image": "http://placehold.it/32x32",
"labels": ["green", "yellow", "blue"],
"labels_link": ["http://sulfax.com/labels/green","http://sulfax.com/labels/yellow","http://sulfax.com/labels/blue"],
}
]
How do I convert this json data to yaml using PowerShell where each json object will be converted to yaml and saved as yaml in its own file with the file name being the value of the title keys properties?
When I run the following command ($json | ConvertFrom-Json) | ConvertTo-YAML (where the ConvertTo-YAML function is taken from the simpletalk website), this is the output I get.
Output
---
id: 0
name: 'Cofine'
title: 'laboris minim qui nisi esse amet non'
description: Consequat laborum quis exercitation culpa. Culpa esse sint consectetur deserunt non.
website: 'cofine.com'
image: 'http://placehold.it/32x32'
labels:
- 'blue'
- 'red'
labels_link:
- 'http://cofine.com/labels/blue'
- 'http://cofine.com/labels/red'
---
id: 1
name: 'Zomboid'
title: 'adipisicing mollit esse aliquip ullamco nisi laboris'
description: Enim consectetur eu commodo officia. Id pariatur proident nostrud occaecat adipisicing voluptate do nisi incididunt id ex commodo.
website: 'zomboid.com'
image: 'http://placehold.it/32x32'
labels:
- 'red'
labels_link:
- 'http://zomboid.com/labels/red'
---
id: 2
name: 'Sulfax'
title: 'non minim anim irure nulla ad elit'
description: Pariatur anim officia adipisicing Lorem dolor cillum eu ex veniam sint consequat incididunt. Minim mollit reprehenderit mollit sint laboris consequat.
website: 'sulfax.com'
image: 'http://placehold.it/32x32'
labels:
- 'green'
- 'yellow'
- 'blue'
labels_link:
- 'http://sulfax.com/labels/green'
- 'http://sulfax.com/labels/yellow'
- 'http://sulfax.com/labels/blue'
However, the output I am looking for would look like this - where the filename is the value of the title keys properties and the content of the file would be the corresponding json object converted to yaml.
laboris minim qui nisi esse amet non.yaml
---
id: 0
name: 'Cofine'
title: 'laboris minim qui nisi esse amet non'
description: Consequat laborum quis exercitation culpa. Culpa esse sint consectetur deserunt non.
website: 'cofine.com'
image: 'http://placehold.it/32x32'
labels:
- 'blue'
- 'red'
labels_link:
- 'http://cofine.com/labels/blue'
- 'http://cofine.com/labels/red'
---
adipisicing mollit esse aliquip ullamco nisi laboris.yaml
---
id: 1
name: 'Zomboid'
title: 'adipisicing mollit esse aliquip ullamco nisi laboris'
description: Enim consectetur eu commodo officia. Id pariatur proident nostrud occaecat adipisicing voluptate do nisi incididunt id ex commodo.
website: 'zomboid.com'
image: 'http://placehold.it/32x32'
labels:
- 'red'
labels_link:
- 'http://zomboid.com/labels/red'
---
non minim anim irure nulla ad elit.yaml
---
id: 2
name: 'Sulfax'
title: 'non minim anim irure nulla ad elit'
description: Pariatur anim officia adipisicing Lorem dolor cillum eu ex veniam sint consequat incididunt. Minim mollit reprehenderit mollit sint laboris consequat.
website: 'sulfax.com'
image: 'http://placehold.it/32x32'
labels:
- 'green'
- 'yellow'
- 'blue'
labels_link:
- 'http://sulfax.com/labels/green'
- 'http://sulfax.com/labels/yellow'
- 'http://sulfax.com/labels/blue'
---