List to JS object
Turn a list into a JavaScript object literal you can paste straight into code: identifiers stay bare while keys with spaces, dashes, a leading digit or reserved words get quoted, every value is a string, and values can map to the row number, the occurrence count or the item itself.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Object literal
Ready to paste into JavaScript or TypeScript.
Paste a list to build an object
Key/value pairs: 0 · Quoted keys: 0 · Merged duplicates: 0 · Characters: 0
What this tool does
- Turn a column of IDs or field names into an object literal for fixtures, mocks or lookup tables without hand-typing quotes and commas.
- Switch the value mode to number every item or to record how often each item appears.
- Paste key=value pairs to get a config object; keys that are not valid identifiers are quoted automatically so the code still parses.
Example
Input
apple banana cherry
Output
const list = {
apple: "1",
banana: "2",
cherry: "3",
};Values default to the 1-based row number and the variable is `list`; keys that are valid identifiers stay unquoted, everything else gets double quotes.
Frequently asked questions
Which keys get quoted?
Anything that fails the identifier rule (spaces, dashes, dots, a leading digit, non-ASCII) plus JavaScript reserved words such as class, default or for is written as a quoted key, and quotes and backslashes inside the value are escaped too — the generated code always parses.
Why is every value a string?
Each list item is text by nature; keeping it a string means values like 007 or 1.10 do not lose their leading zero or trailing digit when parsed as numbers. Convert them in code when you actually need numbers.
What happens to duplicate keys?
Only the first occurrence is emitted; the rest are merged and counted in the “merged duplicates” stat. An object literal would keep just the last one anyway, so merging up front avoids ambiguous output.
Can it generate nested objects or arrays?
No — this only produces a flat set of key/value pairs. Use a JSON-to-code tool for nested structures, or prepare the nested text first and paste it in.
Keywords:列表转js对象list to objectjs 对象对象字面量object literal键名加引号合法标识符代码生成