forked from Jan-Bruun-Andersen/elastic-legacy-to-composable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjq-compactor.pl
66 lines (51 loc) · 1.2 KB
/
jq-compactor.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/perl -0
=pod
=head1 NAME
jq-compactor
=head1 DESCRIPTION
jq-compactor is a script that will partially compact a pretty-printed
JSON file as produced by L<jq|https://stedolan.github.io/jq/> by putting
the inner-most level of braces on a single line.
The script was found in a
L<discussion on GitHub|https://github.com/stedolan/jq/issues/643#issuecomment-392384015>
on how to partially compact the JSON produced by 'jq':
=head1 EXAMPLE
An input like this:
{
"mappings": {
"dynamic": "true",
"properties": {
"DestinationIPAddress": {
"type": "ip"
},
"Device IP Address": {
"type": "ip"
},
"NAS-IP-Address": {
"type": "ip"
}
}
}
}
will be turned into this more compact form:
{
"mappings": {
"dynamic": "true",
"properties": {
"DestinationIPAddress": { "type": "ip" },
"Device IP Address": { "type": "ip" },
"NAS-IP-Address": { "type": "ip" }
}
}
}
=head1 AUTHOR
yanOnGithub - L<https://github.com/yanOnGithub>
=cut
while(<>) {
my @array = split(/(\{[^{}]+\})/, $_);
for(my $a = 1; $a < scalar(@array); $a += 2) {
$array[$a] =~ s!^\s+!!mg;
$array[$a] =~ s![\r\n]+! !g;
}
print join "", @array;
}