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
// Desc: DoScan language file
// lang: DE
// Date: 2012-07-12T1755
//
{ "version" : 37,
"title" : {
"description" : "Name der Anwendung",
"message" : "DoScan"
},
"purpose" : {
"description" : "Funktionalität der Anwendung",
"message" : "Diese Anwendung erlaubt das Scannen nach Texten:<br>
<ul>
<li>Im Netzwerk
<li>Lokal
<li>In der Shell
</ul>
Weiteres unter <a href=\"/manula/scndo\">Manual</a> <br>
"
},
//
"copyright" : {
"description" : "Copyright und Rechte",
"message" : "<p>All Rights reserved.<br>
(c)2013 Example Gmbh, Oxdorf
</p>"
},
"prompt_for_name": {
"message": "What's your name?",
"description": "Ask for the user's name"
},
"hello": {
"message": "Hello, $USER$",
"description": "Greet the user",
"placeholders": {
"user": {
"content": "$1",
"example": "Cira"
}
}
}
//
}
1 2 3 4 5 6 7 8 9 10 11
use URI::Escape qw(uri_escape); my $data = do{ local $/ = undef; <DATA>}; print uri_escape $data; # eine Zeile __DATA__ Das ist ein mehrzeiliger Text
1 2 3 4 5 6 7 8 9 10 11 12 13
use YAML::XS qw/ Load /; use JSON::PP; my $file = "jsonyaml.txt"; open my $fh, "<", $file or die $!; my $yaml = do { local $/; <$fh> }; close $fh; $yaml =~ s{^ *//.*$}{}mg; my $data = Load($yaml); my $coder = JSON::PP->new->ascii->pretty; print $coder->encode($data);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/perl use strict; use warnings; use 5.010; use utf8; use YAML::XS qw/ Load /; use JSON::PP; my $yaml = do { local $/; <> }; $yaml =~ s{^ *//.*$}{}mg; my $data = Load($yaml); my $coder = JSON::PP->new; $coder = $coder->canonical(1); $coder = $coder->ascii->pretty; print $coder->encode($data);
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
use Syntax::Construct qw(\R); use File::Slurper qw(read_binary); use JSON::PP qw(); use Regexp::Common qw(delimited); my $bin = read_binary 'deperlorg-t20491-m188694.json'; { my @delim; # find quoted strings that contain unbackslashed whitespace # while also ignoring escaped quotes while ($bin =~ /$RE{delimited}{-delim=>'"'}{-keep}/cgms) { my $delimited = $1; push @delim, $delimited if $delimited =~ qr/\R|\t/; } for my $delimited (@delim) { substr $bin, (index $bin, $delimited), (length $delimited), # fix escapes ($delimited =~ s/\R/\\r\\n/gr =~ s/\t/\\t/gr); } } # ::PP skips // comments use DDS; Dump(JSON::PP->new->utf8->decode($bin)); __END__ { copyright => { description => 'Copyright und Rechte', message => "<p>All Rights reserved.<br>" . "\r\n\t\t\t\t\t(c)2013 Example Gmbh, Oxdorf" . "\r\n </p>" }, hello => { description => 'Greet the user', message => 'Hello, $USER$', placeholders => { user => { content => '$1', example => 'Cira' } } }, prompt_for_name => { description => 'Ask for the user\'s name', message => 'What\'s your name?' }, purpose => { description => "Funktionalit\344t der Anwendung", message => "Diese Anwendung erlaubt das Scannen nach Texten:" . "<br>\r\n<ul>\r\n <li>Im Netzwerk\r\n<li>Lokal\r\n<li>" . "In der Shell\r\n</ul>\r\nWeiteres unter " . "<a href=\"/manula/scndo\">Manual</a> <br>\r\n" }, title => { description => 'Name der Anwendung', message => 'DoScan' }, version => 37 }