API Documentation
Programmatic access to DataValidate Pro conversion and validation tools. All conversions run client-side in your browser.
Overview
DataValidate Pro tools are implemented as client-side JavaScript functions. While we don't provide a traditional REST API, you can use our conversion libraries directly in your own JavaScript/TypeScript projects, or replicate the functionality using the same open-source libraries we use.
This documentation provides code examples for common conversions using popular libraries and command-line tools.
YAML ↔ JSON Conversion
JavaScript / Node.js
Using js-yaml library:
// Install: npm install js-yaml
const yaml = require('js-yaml');
const yamlString = `
name: DataValidate Pro
version: 1.0.0
features:
- YAML converter
- JSON validator
- JWT decoder
`;
try {
const jsonData = yaml.load(yamlString);
console.log(JSON.stringify(jsonData, null, 2));
} catch (error) {
console.error('YAML parsing error:', error.message);
}Python
Using PyYAML library:
# Install: pip install PyYAML
import yaml
import json
yaml_string = """
name: DataValidate Pro
version: 1.0.0
features:
- YAML converter
- JSON validator
- JWT decoder
"""
try:
data = yaml.safe_load(yaml_string)
json_output = json.dumps(data, indent=2)
print(json_output)
except yaml.YAMLError as e:
print(f"YAML parsing error: {e}")Command Line (yq)
Using yq command-line tool:
# Install yq: brew install yq (macOS) or snap install yq (Linux)
# Convert YAML to JSON
yq eval -o=json input.yaml > output.json
# Convert JSON to YAML
yq eval -P input.json > output.yaml
# Pretty print YAML as JSON
cat config.yaml | yq eval -o=jsonCSV ↔ JSON Conversion
JavaScript / Node.js
Using papaparse library:
// Install: npm install papaparse
const Papa = require('papaparse');
const csvString = `name,email,role
John Doe,john@example.com,Developer
Jane Smith,jane@example.com,Designer`;
const result = Papa.parse(csvString, {
header: true,
skipEmptyLines: true,
});
console.log(JSON.stringify(result.data, null, 2));
// Convert JSON to CSV
const jsonData = [
{ name: 'John Doe', email: 'john@example.com', role: 'Developer' },
{ name: 'Jane Smith', email: 'jane@example.com', role: 'Designer' }
];
const csv = Papa.unparse(jsonData);
console.log(csv);Python
Using Python's built-in csv module:
import csv
import json
# CSV to JSON
csv_string = """name,email,role
John Doe,john@example.com,Developer
Jane Smith,jane@example.com,Designer"""
reader = csv.DictReader(csv_string.splitlines())
data = list(reader)
print(json.dumps(data, indent=2))
# JSON to CSV
json_data = [
{"name": "John Doe", "email": "john@example.com", "role": "Developer"},
{"name": "Jane Smith", "email": "jane@example.com", "role": "Designer"}
]
with open('output.csv', 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=['name', 'email', 'role'])
writer.writeheader()
writer.writerows(json_data)Command Line (csvkit)
Using csvkit toolkit:
# Install csvkit: pip install csvkit
# Convert CSV to JSON
csvjson input.csv > output.json
# Convert JSON to CSV
in2csv --format json input.json > output.csv
# Pretty print CSV as JSON
cat data.csv | csvjson | jqXML ↔ JSON Conversion
JavaScript / Node.js
Using xml-js library:
// Install: npm install xml-js
const convert = require('xml-js');
const xmlString = `<?xml version="1.0"?>
<user>
<name>John Doe</name>
<email>john@example.com</email>
<role>Developer</role>
</user>`;
const result = convert.xml2json(xmlString, {
compact: true,
spaces: 2
});
console.log(result);
// Convert JSON to XML
const jsonString = JSON.stringify({ user: { name: 'John', email: 'john@example.com' }});
const xml = convert.json2xml(jsonString, { compact: true, spaces: 2 });
console.log(xml);Python
Using xmltodict library:
# Install: pip install xmltodict
import xmltodict
import json
xml_string = """
John Doe
john@example.com
Developer
"""
data = xmltodict.parse(xml_string)
print(json.dumps(data, indent=2))
# Convert JSON to XML
json_data = {"user": {"name": "John", "email": "john@example.com"}}
xml_output = xmltodict.unparse(json_data, pretty=True)
print(xml_output)JWT Decoding
JavaScript / Node.js
Using jsonwebtoken library:
// Install: npm install jsonwebtoken
const jwt = require('jsonwebtoken');
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
// Decode without verification (for inspection only)
const decoded = jwt.decode(token, { complete: true });
console.log('Header:', decoded.header);
console.log('Payload:', decoded.payload);
// Verify and decode (with secret)
try {
const verified = jwt.verify(token, 'your-secret-key');
console.log('Verified payload:', verified);
} catch (error) {
console.error('Verification failed:', error.message);
}Python
Using PyJWT library:
# Install: pip install PyJWT
import jwt
import json
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
# Decode without verification (for inspection only)
decoded = jwt.decode(token, options={"verify_signature": False})
print(json.dumps(decoded, indent=2))
# Verify and decode (with secret)
try:
verified = jwt.decode(token, "your-secret-key", algorithms=["HS256"])
print("Verified:", json.dumps(verified, indent=2))
except jwt.InvalidTokenError as e:
print(f"Verification failed: {e}")Command Line (base64)
Basic JWT decoding without verification:
# Decode JWT without verification (base64 decode)
# Split token into parts and decode payload
TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
# Extract payload (second part)
PAYLOAD=$(echo $TOKEN | cut -d'.' -f2)
# Decode base64 (add padding if needed)
echo $PAYLOAD | base64 -d | jq
# Full one-liner
echo $TOKEN | cut -d'.' -f2 | base64 -d | jqBase64 Encoding/Decoding
JavaScript / Node.js
// Node.js built-in Buffer
// Encode
const text = "Hello, DataValidate Pro!";
const encoded = Buffer.from(text).toString('base64');
console.log('Encoded:', encoded);
// Decode
const decoded = Buffer.from(encoded, 'base64').toString('utf-8');
console.log('Decoded:', decoded);
// URL-safe Base64
const urlSafe = encoded.replace(/+/g, '-').replace(///g, '_').replace(/=/g, '');
console.log('URL-safe:', urlSafe);Python
import base64
# Encode
text = "Hello, DataValidate Pro!"
encoded = base64.b64encode(text.encode()).decode()
print(f"Encoded: {encoded}")
# Decode
decoded = base64.b64decode(encoded).decode()
print(f"Decoded: {decoded}")
# URL-safe Base64
url_safe = base64.urlsafe_b64encode(text.encode()).decode()
print(f"URL-safe: {url_safe}")Command Line
# Encode
echo "Hello, DataValidate Pro!" | base64
# Decode
echo "SGVsbG8sIERhdGFWYWxpZGF0ZSBQcm8hCg==" | base64 -d
# Encode file
base64 input.txt > output.b64
# Decode file
base64 -d input.b64 > output.txtRecommended Libraries
JavaScript / TypeScript
- •
js-yaml- YAML parser and dumper - •
papaparse- Powerful CSV parser - •
xml-js- XML to JSON converter - •
jsonwebtoken- JWT implementation
Python
- •
PyYAML- YAML parser and emitter - •
csv- Built-in CSV module - •
xmltodict- XML to dict converter - •
PyJWT- JWT implementation
Try Our Online Tools
Looking for a quick conversion without writing code? Try our browser-based tools:
Need more advanced text processing tools? Check out TextDiff for powerful text comparison and diff utilities.
For more developer tools, visit loadtime.dev.