json-parser-yaml-converter

1.3.0 • Public • Published

TFA: Better JSON Parser & JSON to YAML Converter

Author

License

ISC

Better JSON Parser

A JSON Parser which tells you if the JSON is bad formatted or not. If it is, it will tell you which line has the error and what was expected.

  • Example on CLI:
npx checkjson jsonFile.json 

Will show you the error if there is one, or it will just tell you if the JSON is well formatted.

  • Example on Node:
import { jsonParse } from '@ull-esit-pl-2324/tfa-juan-rodriguez-suarez-alu0101477596';
let obj = jsonParse('jsonFile.json');

If it fails, it will throw an error with the line, column, the expected tokens and the token that was found:

try {
  let obj = jsonParse('jsonFile.json');
} catch (error) {
  console.log(error.token, error.expected, error.line, error.column);
}

JSON to YAML Converter

A JSON to YAML converter that will convert a JSON file to a YAML file.

  • Example on CLI:
npx json2yaml jsonFile.json

Will create a YAML file with the same name as the JSON file but with the .yaml extension.

With the -o flag you can specify the output file:

npx json2yaml jsonFile.json -o yamlFile.yaml

Will create a YAML file with the name yamlFile.yaml.

In both cases, if the JSON file is bad formatted, it will throw an error similar to the one in the JSON Parser.

  • Example on Node:
import { jsonToYaml } from '@ull-esit-pl-2324/tfa-juan-rodriguez-suarez-alu0101477596';
jsonToYaml('jsonFile.json', 'yamlFile.yaml');

If it fails, it will throw an error similar to the one in the JSON Parser.

Look for keys in JSON

A function that will look for a key in a JSON file and return the value of that key.

  • Example on CLI:
npx searchkey jsonFile.json key

Will print the value of all the keys matching the given key and its value.

Readme

Keywords

Package Sidebar

Install

npm i json-parser-yaml-converter

Weekly Downloads

7

Version

1.3.0

License

ISC

Unpacked Size

14.2 MB

Total Files

147

Last publish

Collaborators

  • juanrguezsu7