Repository: gcanti/io-ts-types (ts)

Issue:
Export `Json` from `JsonFromString`
## 🚀 Feature request

### Current Behavior

The `Json` codec is used in the definition of `JsonFromString`, but it's not exported, and it makes it hard to depend on `JSONFromString` because it's useful to assert for example that "I care that this key exists, but the value of that key is Json too`
https://github.com/gcanti/io-ts-types/blob/master/src/JsonFromString.ts#L27

### Desired Behavior

export that line.


Pull request description:
export `Json`, `JsonRecord`, `JsonArray` codecs from `JsonFromString`…
… module, closes #156


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0c43e9c..ebdd9cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,11 @@
 **Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a
 high state of flux, you're at risk of it changing without notice.
 
+# 0.5.15
+
+- **Polish**
+  - export `Json`, `JsonRecord`, `JsonArray` codecs from `JsonFromString` module, closes #156 (@gcanti)
+
 # 0.5.14
 
 - **New Feature**
diff --git a/docs/modules/JsonFromString.ts.md b/docs/modules/JsonFromString.ts.md
index 9029cde..e9ccd20 100644
--- a/docs/modules/JsonFromString.ts.md
+++ b/docs/modules/JsonFromString.ts.md
@@ -15,7 +15,10 @@ Added in v0.5.14
 - [JsonArray (interface)](#jsonarray-interface)
 - [JsonRecord (interface)](#jsonrecord-interface)
 - [Json (type alias)](#json-type-alias)
+- [Json](#json)
+- [JsonArray](#jsonarray)
 - [JsonFromString](#jsonfromstring)
+- [JsonRecord](#jsonrecord)
 
 ---
 
@@ -53,6 +56,26 @@ export type Json = boolean | number | string | null | JsonArray | JsonRecord
 
 Added in v0.5.14
 
+# Json
+
+**Signature**
+
+```ts
+export const Json: t.Type<Json> = ...
+```
+
+Added in v0.5.15
+
+# JsonArray
+
+**Signature**
+
+```ts
+export const JsonArray: t.Type<JsonArray> = ...
+```
+
+Added in v0.5.15
+
 # JsonFromString
 
 **Signature**
@@ -62,3 +85,13 @@ export const JsonFromString: t.Type<Json, string, string> = ...
 ```
 
 Added in v0.5.14
+
+# JsonRecord
+
+**Signature**
+
+```ts
+export const JsonRecord: t.Type<JsonRecord> = ...
+```
+
+Added in v0.5.15
diff --git a/package.json b/package.json
index 9514f76..664b673 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "io-ts-types",
-  "version": "0.5.14",
+  "version": "0.5.15",
   "description": "A collection of codecs and combinators for use with io-ts",
   "main": "lib/index.js",
   "module": "es6/index.js",
diff --git a/src/JsonFromString.ts b/src/JsonFromString.ts
index d1dea00..6f245ae 100644
--- a/src/JsonFromString.ts
+++ b/src/JsonFromString.ts
@@ -22,9 +22,20 @@ export interface JsonRecord {
  */
 export interface JsonArray extends ReadonlyArray<Json> {}
 
-const JsonArray: t.Type<JsonArray> = t.recursion('JsonArray', () => t.readonlyArray(Json))
-const JsonRecord: t.Type<JsonRecord> = t.recursion('JsonRecord', () => t.record(t.string, Json))
-const Json: t.Type<Json> = t.union([t.boolean, t.number, t.string, t.null, JsonArray, JsonRecord], 'Json')
+/**
+ * @since 0.5.15
+ */
+export const JsonArray: t.Type<JsonArray> = t.recursion('JsonArray', () => t.readonlyArray(Json))
+
+/**
+ * @since 0.5.15
+ */
+export const JsonRecord: t.Type<JsonRecord> = t.recursion('JsonRecord', () => t.record(t.string, Json))
+
+/**
+ * @since 0.5.15
+ */
+export const Json: t.Type<Json> = t.union([t.boolean, t.number, t.string, t.null, JsonArray, JsonRecord], 'Json')
 
 /**
  * @since 0.5.14


Test patch:
diff --git a/test/JsonFromString.ts b/test/JsonFromString.ts
index 8faf0cc..d4a5436 100644
--- a/test/JsonFromString.ts
+++ b/test/JsonFromString.ts
@@ -1,6 +1,7 @@
 import * as assert from 'assert'
-import { JsonFromString } from '../src'
+import { JsonFromString, JsonArray } from '../src'
 import { assertFailure, assertSuccess } from './helpers'
+import * as t from 'io-ts'
 
 describe('JSONFromString', () => {
   it('is', () => {
@@ -34,4 +35,14 @@ describe('JSONFromString', () => {
     const T = JsonFromString
     assert.deepEqual(T.encode({}), '{}')
   })
+
+  it('#156', () => {
+    const C = JsonFromString.pipe(
+      t.type({
+        a: JsonArray
+      })
+    )
+    assertSuccess(C.decode('{"a":[]}'), { a: [] })
+    assertFailure(C, '{"a":1}', ['Invalid value 1 supplied to : pipe(JsonFromString, { a: JsonArray })/a: JsonArray'])
+  })
 })