# @sil/jsonto

> Convert json to....

Latest version **0.1.0** (published 2020-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sil/jsonto
pnpm add @sil/jsonto
yarn add @sil/jsonto
bun add @sil/jsonto
```

Provides the command `jsonto`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-12-16 |
| First published | 2020-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 24.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sil van Diepen |
| Maintainers | hacobvandipyan, silvandiepen |
| Keywords | convert, json |

## Links

- npm: https://www.npmjs.com/package/@sil/jsonto
- Repository: https://github.com/silvandiepen/jsonto
- Homepage: https://github.com/silvandiepen/jsonto#readme
- Issues: https://github.com/silvandiepen/jsonto/issues
- npm.io page: https://npm.io/package/@sil/jsonto

## Dependencies (2)

- [ejs](https://npm.io/package/ejs.md) ^3.1.5
- [cli-block](https://npm.io/package/cli-block.md) ^1.2.3

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.0 (latest) — 2020-12-16
- 0.0.3 — 2020-12-15
- 0.0.2 — 2020-12-15
- 0.0.1 — 2020-12-15

## README

# JSON To...

Convert JSON files to anything you want!

JSON to makes it possible to create any type of file using JSON data. We provide the tool, you provide the input and the template.

### Why?

It is initially made to use create Sass/SCSS files from JSON. Defining settings in a json file which can be used by a frontend and automatically generate SCSS settings files.

### Usage (NPM)

1. Install the script

```bash
npm install @sil/jsonto --save-dev
```

2. Create a [template](#template)

3. Add the script to your package.json

```json
{
    ...
    "scripts": {
        ...
        "build:config": "jsonto src/config.json src/scss/config.scss src/templates/my-config.template"
        ...
    }
    ...
}
```

4. Run it!

```bash
npm run build:config
```

### Command (NPX)

You can run json also using NPX. Example command;

```bash
npx @sil/jsonto source.json output.scss example.template
```

### Arguments

JsonTo needs 3 arguments as in the example above

1. Source (json file)
2. Output (.scss)
3. Template file


### Template

The template engine uses (EJS)[https://ejs.co], so you can add anything in the file you want. A simple example to build a Sass config file;

**my-config.template**

An example to use, this will just generate the data as is.

```
$my-config: (
    <% Object.keys(data).forEach((key, index)=>{ -%>
        "<%- key %>": "<%- data[key]%>"<% if(index == data.length){ %>,<%}%>
    <% }) -%>
)!default;
```

But you can also use the sassData to generate the settings

```
$my-sass-configs: (
  <% if (data) { -%>
    <%- sassData %>
  <% } -%>
) !default;
```

### SCSS

For now, JSON To has been mainly used for SCSS templates. Thats why it provides a few extra functions to use with Sass. Because a json object isn't 1:1 usable in SCSS.

|                | type     | Description                                         |
| -------------- | -------- | --------------------------------------------------- |
| `toSassValue`  | function | Converts a value to a valid Sass value              |
| `toSassObject` | function | Converts a whole object to a Sass object            |
| `sassData`     | string   | The full data object converted to a valid Sass list |

---
_Source: https://npm.io/package/@sil/jsonto · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
