# jsonconst

> Library converting a JSON file into a strongly typed constant in the target language (currently supported: Typescript and C#). Intended for cross-platform config files, but useful for any constant definitions

Latest version **0.0.29** (published 2017-02-01) · 0 weekly downloads

## Install

```sh
npm install jsonconst
pnpm add jsonconst
yarn add jsonconst
bun add jsonconst
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.29 |
| Published | 2017-02-01 |
| First published | 2016-10-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Thomas Schaumburg |
| Maintainers | tschaumburg |

## Links

- npm: https://www.npmjs.com/package/jsonconst
- Repository: https://github.com/tschaumburg/jsonconst
- Homepage: https://github.com/tschaumburg/jsonconst#readme
- Issues: https://github.com/tschaumburg/jsonconst/issues
- npm.io page: https://npm.io/package/jsonconst

## Dependencies (2)

- [strip-json-comments](https://npm.io/package/strip-json-comments.md) ^2.0.1
- [json-schema-ref-parser](https://npm.io/package/json-schema-ref-parser.md) ^3.1.2

## Recent versions

- 0.0.29 (latest) — 2017-02-01
- 0.0.28 — 2017-02-01
- 0.0.27 — 2017-02-01
- 0.0.26 — 2017-02-01
- 0.0.25 — 2017-02-01
- 0.0.24 — 2016-12-02
- 0.0.23 — 2016-12-02
- 0.0.22 — 2016-12-01
- 0.0.21 — 2016-11-24
- 0.0.20 — 2016-11-24
- 0.0.19 — 2016-11-24
- 0.0.18 — 2016-11-24
- 0.0.17 — 2016-11-23
- 0.0.16 — 2016-11-23
- 0.0.15 — 2016-11-23
- … 14 more at https://npm.io/package/jsonconst/versions

## README

# jsonconst


This package provides a Javascript library that you can call from your own code
   ```javascript
   const file = require("file");
   function compile_config()
   {
       var json = file.read("foo.json");
       var ts = jsonconst.generate(json, "typescript", null, null);
       file.write("foo.ts", ts);
   }
   ```

###JSON schema
``Jsonconst`` allows you to specify the *JSON schema* for your JSON file:

```json
{
   $schema: "./myschema.schema.json",
   'firstname': "John"
}
```

Doing so has a number of advantages, as listed below.

####Catching type errors
Without a schema, any field can take any value:
```json
{
   'numericValue': "foo",
   'stringValue': 41
}
```

With a schema, mistakes like the above are caught during compilation:
```json
{
   $schema: "./myConfig.schema.json",
   'numericValue': "foo",
   'stringValue': 41
}
```

And if your editor supports JSON schemas, you will get error feedback when editing:

FIG

####Intellisense
JSON schemas allow you to add descriptions to fields - and if your editor supports it, these descriptions
willl be displayed:

FIG

The descriptions will also be passed on to code generation:

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