JSON to MATLAB Converter

Transform JSON data into MATLAB code

JSON Input

MATLAB Output

About JSON to MATLAB Converter

Convert JSON data to MATLAB code with automatic detection of matrices, cell arrays, and struct formats. Perfect for data analysis, scientific computing, and MATLAB integration.

Key Features

  • Smart Type Detection: Automatically chooses between matrix, cell array, or struct
  • Numeric Arrays: Converts numeric JSON arrays to MATLAB matrices
  • Mixed Types: Handles mixed-type data with cell arrays
  • Struct Support: Converts JSON objects to MATLAB structs
  • String Escaping: Properly escapes single quotes in strings
  • Custom Variable Names: Specify your own variable names
  • File Upload: Upload JSON files directly or paste data
  • Instant Preview: Real-time conversion as you type

How to Use

  1. Input JSON Data: Paste your JSON data or upload a .json file
  2. Set Variable Name: Optionally customize the MATLAB variable name
  3. Review Output: The MATLAB code updates automatically
  4. Copy or Download: Use the Copy or Download button to save your MATLAB code

Conversion Examples

Example 1: Numeric Array to Matrix

JSON Input:

[1, 2, 3, 4, 5]

MATLAB Output:

data = [1, 2, 3, 4, 5];

Example 2: Object to Struct

JSON Input:

{"name": "John", "age": 30, "scores": [85, 90, 95]}

MATLAB Output:

data = struct();
data.name = 'John';
data.age = 30;
data.scores = [85, 90, 95];

Example 3: Array of Objects to Struct with Arrays

JSON Input:

[
  {"name": "John", "age": 28, "score": 95.5},
  {"name": "Jane", "age": 34, "score": 87.3}
]

MATLAB Output:

data = struct();
data.name = {'John', 'Jane'};
data.age = [28, 34];
data.score = [95.5, 87.3];

Data Type Handling

  • Numbers: Converted to MATLAB numeric values
  • Strings: Wrapped in single quotes with proper escaping
  • Booleans: Converted to true/false
  • Null/Undefined: Converted to NaN
  • Arrays: Numeric arrays become matrices, mixed arrays become cell arrays
  • Objects: Converted to MATLAB structs

Common Use Cases

  • Data Analysis: Import JSON data into MATLAB for analysis
  • API Integration: Convert API responses to MATLAB format
  • Scientific Computing: Prepare data for MATLAB computations
  • Machine Learning: Convert datasets for MATLAB ML toolbox
  • Visualization: Import data for MATLAB plotting and visualization

Variable Naming

Variable names are automatically sanitized to be valid MATLAB identifiers. Invalid characters are replaced with underscores.

Privacy & Security

All conversions happen locally in your browser. Your JSON data is never uploaded to any server, ensuring complete privacy and security.