Thread JSON: mehrzeilige Werte in einzeilige umwandeln (6 answers)
Opened by GwenDragon at 2018-07-28 13:28

Daxim
 2018-07-30 11:23
#188700 #188700
User since
2007-08-01
114 Artikel
BenutzerIn
[Homepage]
user image
Kürzeste Lösung:

Code (perl): (dl )
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
}

View full thread JSON: mehrzeilige Werte in einzeilige umwandeln