├── .prettierignore ├── public ├── robots.txt ├── favicon.svg └── favicon-dark.svg ├── .gitignore ├── .prettierrc ├── src ├── main.ts ├── lib.ts ├── App.vue └── Code.vue ├── .editorconfig ├── README.md ├── tsconfig.json ├── vite.config.ts ├── package.json ├── uno.config.ts ├── index.html ├── LICENSE └── pnpm-lock.yaml /.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | 4 | auto-imports.d.ts 5 | 6 | .DS_Store 7 | Thumbs.db 8 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "trailingComma": "all", 4 | "semi": true, 5 | "singleQuote": true 6 | } 7 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue'; 2 | import App from './App.vue'; 3 | 4 | import '@unocss/reset/tailwind.css'; 5 | import 'uno.css'; 6 | 7 | createApp(App).mount('#app'); 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 4 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | charset = utf-8 10 | 11 | [*.{yml,yaml,md}] 12 | indent_style = space 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JSON to Nix 2 | 3 | A web app to quickly convert JSON to Nix values. And yes I now know there is [a built-in](https://noogle.dev/f/builtins/fromJSON) for that. But like, on the web amiright? 4 | 5 | ## Development 6 | 7 | ``` 8 | git clone https://github.com/uncenter/json-to-nix.git 9 | cd json-to-nix 10 | pnpm install 11 | pnpm dev 12 | ``` 13 | 14 | ## License 15 | 16 | [MIT](LICENSE) 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "jsx": "preserve", 5 | "lib": ["DOM", "ESNext"], 6 | "module": "ESNext", 7 | "moduleResolution": "bundler", 8 | "resolveJsonModule": true, 9 | "types": ["vite/client"], 10 | "allowJs": true, 11 | "strict": true, 12 | "strictNullChecks": true, 13 | "noUnusedLocals": true, 14 | "esModuleInterop": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "skipLibCheck": true 17 | }, 18 | "exclude": ["dist", "node_modules"] 19 | } 20 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | 3 | import Vue from '@vitejs/plugin-vue'; 4 | import AutoImport from 'unplugin-auto-import/vite'; 5 | import UnoCSS from 'unocss/vite'; 6 | 7 | export default defineConfig({ 8 | plugins: [ 9 | // https://github.com/vitejs/vite-plugin-vue 10 | Vue(), 11 | 12 | // https://github.com/unplugin/unplugin-auto-import 13 | AutoImport({ 14 | imports: ['vue', '@vueuse/core'], 15 | dts: true, 16 | vueTemplate: true, 17 | }), 18 | 19 | // https://github.com/unocss/unocss 20 | UnoCSS(), 21 | ], 22 | }); 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "private": true, 4 | "packageManager": "pnpm@9.4.0", 5 | "scripts": { 6 | "build": "vite build", 7 | "dev": "vite", 8 | "format": "prettier --write ." 9 | }, 10 | "dependencies": { 11 | "@vueuse/core": "^12.2.0", 12 | "shiki": "1.24.4", 13 | "tiny-jsonc": "^1.0.1", 14 | "vue": "^3.5.13" 15 | }, 16 | "devDependencies": { 17 | "@iconify-json/carbon": "^1.2.5", 18 | "@unocss/reset": "^0.65.3", 19 | "@vitejs/plugin-vue": "^5.2.1", 20 | "prettier": "^3.4.2", 21 | "typescript": "^5.7.2", 22 | "unocss": "^0.65.3", 23 | "unplugin-auto-import": "^0.19.0", 24 | "vite": "^6.0.6" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /uno.config.ts: -------------------------------------------------------------------------------- 1 | import { 2 | defineConfig, 3 | presetAttributify, 4 | presetIcons, 5 | presetUno, 6 | presetWebFonts, 7 | transformerDirectives, 8 | } from 'unocss'; 9 | 10 | export default defineConfig({ 11 | shortcuts: { 12 | 'border-base': 'border-gray:30', 13 | 'bg-active': 'bg-gray:10', 14 | 'text-faded': 'text-gray', 15 | 'text-primary': 'text-orange:500', 16 | }, 17 | presets: [ 18 | presetUno(), 19 | presetAttributify(), 20 | presetIcons({ 21 | scale: 1.2, 22 | warn: true, 23 | }), 24 | presetWebFonts({ 25 | fonts: { 26 | sans: 'DM Sans', 27 | serif: 'DM Serif Display', 28 | mono: 'DM Mono', 29 | }, 30 | }), 31 | ], 32 | transformers: [transformerDirectives()], 33 | }); 34 | -------------------------------------------------------------------------------- /src/lib.ts: -------------------------------------------------------------------------------- 1 | export function nixify(value: unknown, level: number = 1): string | undefined { 2 | const indent = ' '.repeat(level); 3 | const subindent = ' '.repeat(level - 1); 4 | if ( 5 | typeof value === 'string' || 6 | typeof value === 'number'|| 7 | value === null || 8 | value === true || 9 | value === false 10 | ) 11 | return `${JSON.stringify(value)}`; 12 | else if (Array.isArray(value)) 13 | return `[\n${value.map((item) => `${indent}${nixify(item, level + 1)}`).join('\n')}\n${subindent}]`; 14 | else { 15 | let nix = '{\n'; 16 | for (const [k, v] of Object.entries( 17 | value as Record, 18 | )) { 19 | // https://nix.dev/manual/nix/2.18/language/values.html#attribute-set 20 | nix += `${indent}${k.match(/^[a-zA-Z0-9_'-]*$/) ? k : `"${k}"`} = ${nixify(v, level + 1)};\n`; 21 | } 22 | return nix?.trimEnd() + `\n${subindent}}`; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | JSON to Nix 7 | 8 | 9 | 10 | 11 |
12 | 15 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 uncenter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 49 | 50 | 59 | -------------------------------------------------------------------------------- /public/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /public/favicon-dark.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/Code.vue: -------------------------------------------------------------------------------- 1 | 69 | 70 |