yaml stream with multi-file output

591 views
Skip to first unread message

Raphael Bauduin

unread,
Oct 30, 2019, 9:55:01 AM10/30/19
to Jsonnet
Hi,

I would like to generate multiple files, one of which needing to be a YAML stream.
I found this https://github.com/google/jsonnet/issues/637 but it doesn't seem to do what I need (I'm using the Go version of jsonnet).

Here's my jsonnet file:

$ cat test.jsonnet
{
  'foo.json': std.manifestJson({bar: 'a'}),
  'some.yaml': std.manifestYamlDoc([{something: ['a', 'b', 'c']}, {second: "object in stream"} , {third: "element"}])
}

I compile it with `jsonnet test.jsonnet -m . -S -y`

Looking at the resulting yaml, I have:

$ cat some.yaml
- "something":
  - "a"
  - "b"
  - "c"
- "second": "object in stream"
- "third": "element"

But I hope to have something like

---
{
   "something": [
      "a",
      "b",
      "c"
   ]
}
---
{
   "second": "object in stream"
}
---
{
   "third": "element"
}
...

Which is what I get running jsonnet -y on the file

 [{something: ['a', 'b', 'c']}, {second: "object in stream"} , {third: "element"}]

Do I miss something obvious here?

Thanks in advance for your help

Raphaël

Dave Cunningham

unread,
Oct 30, 2019, 9:56:47 AM10/30/19
to Raphael Bauduin, Jsonnet
Use std.manifestYamlStream





--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/4f6d7999-2e4c-43eb-9e0f-2e323b357fe6%40googlegroups.com.

Raphael Bauduin

unread,
Oct 30, 2019, 10:08:03 AM10/30/19
to Jsonnet
Hi,

It works indeed ( that was a fast answer, thanks! :-)

I'm now trying to limit the changes to my jsonnet files to only the parts specifying a yaml stream. So I do this:

$ cat test.jsonnet
{
  'foo.json': {bar: 'a'},
  'some.yaml': std.manifestYamlStream([{something: ['a', 'b', 'c']}, {second: "object in stream"} , {third: "element"}])
}
$ jsonnet test.jsonnet -m . -y
./foo.json
./some.yaml
$ cat some.yaml
"---\n\"something\":\n- \"a\"\n- \"b\"\n- \"c\"\n---\n\"second\": \"object in stream\"\n---\n\"third\": \"element\"\n...\n"
$ yq r - < some.yaml > final.yaml
$ cat final.yaml
---

"something":
- "a"
- "b"
- "c"
---
"second": "object in stream"
---
"third": "element"
...


Is that the right way to do it?
Use std.manifestYamlStream

To unsubscribe from this group and stop receiving emails from it, send an email to jso...@googlegroups.com.

Dave Cunningham

unread,
Oct 30, 2019, 10:20:38 AM10/30/19
to Raphael Bauduin, Jsonnet
The right way to do it would be to use -S and std.manifestJson, but if you don't want to do that then yes you have to do the JSON string -> string conversion in a subsequent pass.  You can also do the conversion on the single yaml file with jsonnet -S instead of yq to cut down on your dependencies.


To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/2617b952-4fd9-4a31-8256-d1746ba963a2%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages