I have the following JSON data:
{\"id\":\"111\",\"case\":\"Y\",\"custom\":{\"speech invoked\":\"no\",\"input method\":\"hard\",\"session ID\":\"420\"}}
Using Perl and its JSON module:
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
use JSON;
my $input = << '__JSON__';
{"id":"111","case":"Y","custom":{"speech invoked":"no","input method":"hard","session ID":"420"}}
__JSON__
my $struct = decode_json($input);
my @header = grep ! ref $struct->{$_}, keys %$struct;
push @header, map keys %{ $struct->{$_} },
grep ref $struct->{$_},
keys %$struct;
my @row = grep ! ref, values %$struct;
push @row, map values %$_, grep ref, values %$struct;
say join ',', @header;
say join ',', @row;