Data type converters for programmers
These converters answer the small questions that come up all the time when writing backend and frontend code: how does this text turn into a number, why is this value true or false, how do I turn an object into a JSON string and back. Type or paste a value, and the result appears at once. Everything runs in your browser, so your data is never sent anywhere.
What is included
- String to Number: compares
parseInt,parseFloat,Number()and the unary plus on the same input, and shows when the result is NaN (not a number). - Number to String:
toString,toFixed, locale formatting, exponential form and other bases. - Boolean Conversion: how values become true or false in JavaScript and Python, plus a word-based reading of "yes", "no", "1", "0", "on" and "off".
- Type Detector: tells you whether a value is an integer, float, boolean, null, date, JSON array or JSON object, or plain text.
- Object / JSON String: serialize an object with
JSON.stringifyor deserialize a string withJSON.parse. It also accepts JavaScript-style objects with single quotes, unquoted keys and trailing commas, and tells you the line and column of a syntax error. - Array / String:
joina list into a string orsplita string into a list. - Base64 and URL encode / decode, both safe for accents and emoji.
- Number Base: decimal, binary, octal and hexadecimal, including very large numbers.
- Unix Timestamp: seconds or milliseconds to a readable date, and back.
- Naming Case: camelCase, PascalCase, snake_case, kebab-case and CONSTANT_CASE.
Serialize and deserialize: object to JSON string and back
Serializing turns an object in memory into text that can be stored or sent over a network. In JavaScript that is JSON.stringify(obj); in Python it is json.dumps(obj). Deserializing does the reverse with JSON.parse(text) or json.loads(text). JSON only holds strings, numbers, booleans, null, arrays and objects, so values such as dates, functions and undefined are changed or dropped when you stringify. Use the Object / JSON String converter to check what comes out before you rely on it.
Common conversion mistakes
parseInt("12px")is 12 butNumber("12px")is NaN. Pick the one that matches how strict you need to be.Boolean("false")is true. Any non-empty text is truthy. Compare the text to "true" instead.- Floating point:
0.1 + 0.2is not exactly 0.3. Round withtoFixedfor display and use integers (cents) for money. - Big integers: JavaScript numbers lose precision above 9,007,199,254,740,991. Use
BigIntor keep such IDs as strings. - Leading zeros: ZIP codes and phone numbers should stay strings, or the zeros vanish.
Frequently asked questions
How do I convert a string to an integer in JavaScript?
Use parseInt(text, 10) to read the whole-number part, or Number(text) to require the entire text to be a number. Check the result with Number.isNaN.
How do I convert a string to a float?
Use parseFloat(text) or Number(text). In Python use float(text). The String to Number converter shows how each one treats your input.
How do I convert an object to a JSON string?
Call JSON.stringify(object). Add a third argument such as 2 to indent the output so it is easy to read.
How do I convert a JSON string back to an object?
Call JSON.parse(text). If the text is not valid JSON it throws an error; this tool shows where the problem is.
How do I convert a string to a boolean?
Do not use Boolean(text), because every non-empty text is true. Compare against the words you accept, such as "true", "yes" or "1". The Boolean Conversion converter shows that approach.
Is my data sent to a server?
No. All conversions run in your browser.