const fs = require('fs'),
      [fileName, jsonPath] = process.argv.slice(2);

if (!fileName) {
    console.log('Please provide a file name.');
    console.log('Usage: json file.json jsonPath');
    process.exit();
}

try {

    const file = fs.readFileSync(fileName).toString(),
          json = JSON.parse(file);

    let result = json;
    
    if (jsonPath) {
        result = jsonPath.split('.').reduce((obj, key) => obj[key], json);
    }

    console.log(result);
    if (typeof result === 'object') {
        console.log('\n');
        if (Array.isArray(result)) {
            console.log('Array', result.length);
        } else {
            console.log('Keys', Object.keys(result))
        }
    }

} catch (err) {
    console.error(err);
}