Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Replace a string that contains special characters

by stevieb (Canon)
on Mar 21, 2017 at 16:09 UTC ( #1185366=note: print w/replies, xml ) Need Help??


in reply to Replace a string that contains special characters

That's some JSON data that is, with an extra } at the end.

Here's an example of how you can load that JSON data as a Perl data structure, then delete items from it, by name, then re-encode the data structure back into a JSON string. Note it's an array reference of hash references:

use warnings; use strict; use JSON; my $json; { local $/; $json = <DATA>; } my $data = decode_json $json; for my $entry (@$data){ delete $entry->{absoluteLimits}; } $json = encode_json $data; print $json; __DATA__ [{"absoluteLimits":{"conditionalLimits":{"bidirVolume":4096000,"name": +"Home"},"resetPeriod":{"volume":"monthly day 15 00:??"}},"sliceVolume +":5120,"subscriptionDate":"29-09-2016"},{"absoluteLimits":{"condition +alLimits":{"bidirVolume":102400000,"name":"Home"},"resetPeriod":{"vol +ume":"2400 hours"}},"description":"Promotion_tariffbasic:29-09-2016,0 +8-01-2017T10:21","name":"1004","sliceVolume":5120,"subscriptionDate": +"30-09-2016T09:21"}]

Output:

[{"subscriptionDate":"29-09-2016","sliceVolume":5120},{"name":"1004"," +subscriptionDate":"30-09-2016T09:21","sliceVolume":5120,"description" +:"Promotion_tariffbasic:29-09-2016,08-01-2017T10:21"}]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1185366]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2022-05-26 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?