in reply to Convert to JSON, without a module?

None of which seem to work.

That's because neither of your examples produces valid JSON strings. To elaborate, strings in JSON are delimited with double quotes, not with single quotes. See http://json.org/.

(Still in general "None of which seem to work." isn't very helpful, you should at least say what happens when you try).

A better approach than blindly (and without looking at the spec) trying stuff would be to either write a minimal JSON implementation of the subset you need, or just copying&pasing code from JSON::PP.

Update: For developement, I have a small script which uses JSON to check the syntax of JSON files. Even if you don't want to install that module everywhere your script is used, you can use it on your development machine for good effect. Here it goes:

#!/usr/bin/perl use strict; use warnings; use JSON; die "Usage: $0 <filename>" if @ARGV != 1; open my $h, '<', $ARGV[0] or die "Can't open file '$ARGV[0]' for reading: $!"; my $contents = do { local $/; <$h> }; close $h or warn $!; my $res = from_json($contents); # vim: ft=perl
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: Convert to JSON, without a module?
by ultranerds (Hermit) on Sep 20, 2010 at 10:22 UTC
    Thanks, will give that a go :)