in reply to Escape $ in JSON::XS decoded

I can't reproduce your problem. There's no need to escape dollars in single quoted strings.
#!/usr/bin/perl use strict; use warnings; my $decoded_json = { 'version' => '1.0', 'feed' => { 'xmlns' => 'http://www.w3.org/2005/Atom', 'updated' => { '$t' => '2020-10-16T19:55:33.294Z' }, 'gs$rowCount' => { '$t' => '1000' }}}; print $decoded_json->{feed}->{updated}->{'$t'}; # 2020-10-16T19:55:33 +.294Z

How should the code return 2019-07-19 when the structure contains 2020-10-16? Maybe the problems happens in the code you didn't show - how do you create the JSON?

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Escape $ in JSON::XS decoded
by johnfl68 (Scribe) on Oct 16, 2020 at 20:58 UTC

    My apologies, I didn't catch that, but it explains part of the problem.

    In the actual JSON file, it reads as follows:

    "updated":{ "$t":"2019-07-19T20:04:56.046Z"

    But when Perl and or JSON::XS is loading the JSON file, it seems to be reinterpreting the $t some how as the current time. I have not declared $t at all.

    I knew what the answer was supposed to be in my head, and my brain just didn't connect that the DataDummper was putting the current time, as I was looking at the raw JSON.

    This just baffles me even more. I'll keep digging.

      I can't reproduce that either. It still returns the value stored in the original JSON, as expected.
      #!/usr/bin/perl use strict; use warnings; use JSON::XS; my $json = '{"feed":{"updated":{"$t":"2019-07-19T20:04:56.046Z"}}}'; my $decoded_json = decode_json($json); print $decoded_json->{feed}->{updated}->{'$t'}; # 2019-07-19T20:04:56 +.046Z
      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      But when Perl and or JSON::XS is loading the JSON file, it seems to be reinterpreting the $t some how as the current time.

      Sorry, but almost certainly not.

      use warnings; use strict; use Data::Dump; use JSON::XS; dd decode_json('{ "updated":{ "$t":"2019-07-19T20:04:56.046Z" } }') __END__ { updated => { "\$t" => "2019-07-19T20:04:56.046Z" } }

      Again, please provide a Short, Self-Contained, Correct Example that we can run that shows otherwise.