Guides › CSV Format, XML to JSON Conversion, and Generating Sensor Test Data
CSV Format, XML to JSON Conversion, and Generating Sensor Test Data
Different jobs call for different data formats. This page covers converting between CSV, XML and JSON, and generating fake data for testing systems.
CSV (comma-separated values)
CSV stores tabular data as comma-separated text. It is the most common format for spreadsheets, analysis tools, data loggers and PLC log exports. The standard is RFC 4180.
timestamp,sensor_id,temperature,humidity 2026-11-29T09:00:00Z,S01,23.5,45.2 2026-11-29T09:01:00Z,S01,23.6,45.0 2026-11-29T09:00:00Z,S02,"21,8",50.1
Rules
- The first row is usually a header with column names.
- Wrap a value in double quotes if it contains a comma, quote or line break.
- Double any quote inside a quoted value:
"He said ""hi""" - Every row should have the same number of columns.
- CSV has no types. Numbers, dates and strings are all text, and the reader decides how to interpret them; that is why leading zeros (
00123) vanish in Excel.
Garbled characters in Excel
Excel misreads UTF-8 CSV files without a BOM (the three bytes EF BB BF at the start), which garbles non-English text. Save with a UTF-8 BOM, or use Data → From Text/CSV and pick 65001 (UTF-8). In some European locales Excel expects semicolons as separators and commas as decimal marks, so values end up in one column.
CSV and JSON conversion
Each CSV row becomes a JSON object, with header names as keys.
[
{"timestamp":"2026-11-29T09:00:00Z","sensor_id":"S01","temperature":"23.5","humidity":"45.2"}
]
- Because CSV has no types, converted values may be strings. Convert them to numbers where needed.
- Nested objects and arrays do not fit in a table. Flatten keys (
location.lat) or store the field as a JSON string. - If objects have different keys, collect all keys as columns and leave missing values empty.
XML and JSON conversion
<sensor id="S01" unit="C">
<temperature>23.5</temperature>
<tag>line1</tag>
<tag>zone-a</tag>
</sensor>
{"sensor": {"@id": "S01", "@unit": "C", "temperature": "23.5", "tag": ["line1", "zone-a"]}}
XML has concepts JSON lacks, so converters follow different conventions.
- Attributes: usually become keys prefixed with
@or_. - Repeated elements: become arrays, but a single occurrence becomes a plain value, so the type changes depending on the data.
- Types: all XML values are text.
- Namespaces, comments and mixed content (text interleaved with tags) do not map cleanly to JSON.
Why test data matters
When building dashboards, databases, alarm logic or charts, real sensors are often not ready yet, and abnormal conditions are hard to create on purpose. Fake data lets you develop and verify first.
Random walk
value[n] = value[n−1] + small random change
Each value drifts a little from the previous one, which mimics slowly changing signals such as temperature, pressure or stock prices. Clamp it to a range, or it can wander off in one direction.
Sine wave
value(t) = center + amplitude × sin(2π × t / period) + noise
Good for periodic data such as daily temperature cycles, vibration or AC signals. A little noise makes it more realistic.
Values worth testing
- Range limits (minimum and maximum) and out-of-range values
- Empty values, nulls and sudden spikes
- Gaps in time and out-of-order timestamps
- Large volumes (thousands to tens of thousands of rows) for performance
This site's CSV generator creates up to 10,000 rows using random walk or sine patterns, and the Mock JSON generator creates up to 1,000 items for API testing, ready to download.
Code formatting tools: SQL, HTML, Markdown
- SQL formatter: breaks a long one-line query at SELECT, FROM, WHERE and JOIN and indents it. Useful when analyzing queries pulled from logs.
- HTML beautify/minify: beautifying indents tags to show structure; minifying strips whitespace and comments to shrink files. Whitespace inside
<pre>is meaningful, so take care when minifying. - Markdown: a simple syntax (
#headings,**bold**,- lists, backtick code) that converts to HTML. Widely used for GitHub READMEs, technical docs and notes.
Tools: CSV ↔ JSON · XML ↔ JSON · SQL formatter · HTML beautifier · Markdown viewer · JSON guide
Try it now: CSV Sensor Data Generator (runs in your browser, no data is sent anywhere)