Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions doc/_stdlib_gen/stdlib-content.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,42 @@ local html = import 'html.libsonnet';
},
],
},
{
name: 'parseCsvWithHeader',
params: ['str', 'delimiter=","', 'overwrite_duplicate_headers=true'],
availableSince: 'upcoming',
description: [
html.p({},|||
Parses a CSV string into JSON. The CSV string would use the passed <code>delimiter</code> to split the columns.
|||),
html.p({},|||
In case of duplicate headers, the value would be overwritten by default. <code>overwrite_duplicate_headers</code>
provides an option handle duplicate headers by appending a sequence number at the end of header.
This example should make it clear:
|||),
html.pre({}, |||
std.parseCsvWithHeaders("head1,head1,head1\nvalue1,value2,value3", overwrite_duplicate_headers=false)
|||),
html.p({},|||
This would result in following output:
|||),
html.pre({}, |||
[
{
"head1": "value1",
"head1__1": "value2",
"head1__2": "value3",
},
],
|||),
],
examples: [
{
input: "std.parseCsvWithHeader('id,name\n1,foo\n2,bar')",
output: std.parseCsvWithHeader('id,name\n1,foo\n2,bar'),
},
],
},
{
name: 'encodeUTF8',
params: ['str'],
Expand Down Expand Up @@ -932,6 +968,45 @@ local html = import 'html.libsonnet';
|||),
],
},
{
name: 'manifestCsv',
params: ['json', 'headers=null'],
availableSince: 'upcoming',
description: [
html.p({}, |||
Convert the given csv compatible json to a CSV.
|||),
html.pre({}, |||
std.manifestCsv(
[
{
"id": 1,
"name": "foo",
"x": "baz",
},
{
"id": 2,
"name": "bar",
},
],
["id", "name"],
|||),
html.p({}, |||
Yields a string containing this CSV:
|||),
html.pre({}, |||
id,name
1,foo
2,bar
|||),
html.p({}, |||
If <code>json</code> param is not a valid csv compatible object, it would be an error.
|||),
html.p({}, |||
The <code>headers</code> param adds is an optional which would default to all fields in the first object.
|||),
],
},
{
name: 'manifestXmlJsonml',
params: ['value'],
Expand Down
2 changes: 2 additions & 0 deletions stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,8 @@ limitations under the License.
sha256(str):: go_only_function,
sha512(str):: go_only_function,
sha3(str):: go_only_function,
parseCsvWithHeader(str, delimiter, overwrite_duplicate_headers):: go_only_function,
manifestCsv(json, headers):: go_only_function,

trim(str):: std.stripChars(str, ' \t\n\f\r\u0085\u00A0'),
}