Convert JSON string to Key / Value Arrays
Python, 27/30
To actually comply with the rules:
keys=lambda x:list(eval(x))
vals=lambda x:eval(x).values()
Python, 30
Just using one function:
lambda x:zip(*eval(x).items())
This will separate the keys from the values and return them in a list.
Python, 7
If returning a dictionary is allowed, then this is all you need:
eval(x)
APL 32
Index origin 1. If you will accept the keys and values being returned as a two row array then a simple one liner will do the job in APL. This takes screen input via ←⍞
⍉((.5×⍴j),2)⍴j←(~j∊'{":;,}')⊂j←⍞
Taking the given example as input:
{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"};
a b c d e f g h
a b c d e f9 g2 h1
Perl 28 bytes
Instead of 2 separate functions to return keys and values, I'm returning both in the form of a hash
.
sub j2h{eval pop=~y/:"/,/dr}
Sample usage:
$_='{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"}';
%h=j2h($_);
print $h{f}; # prints f9
print $h{g}; # prints g2
It even works for arbitrarily deeply nested variables:
$_='{"a":{"b":{"c":"c3","d":"d4"},"c":"c5"},"b":"b6"}';
%h=j2h($_);
print $h{a}{b}{d}; # prints d4
print $h{a}{c}; # prints c5