diff --git a/npm/package.json b/npm/package.json index b9d38b24..f5f739c0 100644 --- a/npm/package.json +++ b/npm/package.json @@ -2,7 +2,7 @@ { "type": "commonjs", "name": "coded-json", - "version": "1.0.2", + "version": "1.0.3", "description": "Coded JSON source code", "main": "out/cjson.js", "types": "out/cjson.d.ts", diff --git a/npm/src/cjson.ts b/npm/src/cjson.ts index 7b187fcb..0273d449 100644 --- a/npm/src/cjson.ts +++ b/npm/src/cjson.ts @@ -19,6 +19,10 @@ export class Cjson extends Is { this.filePath = filePath; this.content = read(this.filePath); this.commaSeparated = this.content.split(","); + + this.decodeKeywords(); + this.decodeRelativePaths(); + this.json = new Json(this.obj); } /** * Root function for decoding keywords @@ -70,9 +74,6 @@ export class Cjson extends Is { * @returns `JSON` if no errors. Else `undefined` */ public deserialize() : JSON | undefined { - this.decodeKeywords(); - this.json = new Json(this.obj); - this.decodeRelativePaths(); return this.obj; } /** diff --git a/tests/npm/package.json b/tests/npm/package.json index fa037935..ec64601d 100644 --- a/tests/npm/package.json +++ b/tests/npm/package.json @@ -12,7 +12,7 @@ "license": "ISC", "dependencies": { "@types/jasmine": "^4.3.1", - "coded-json": "file:coded-json-1.0.2.tgz", + "coded-json": "file:coded-json-1.0.3.tgz", "jasmine": "^4.5.0", "jasmine-spec-reporter": "^7.0.0", "ts-node": "^10.9.1", diff --git a/tests/npm/spec/tests/codedJsonTests.js b/tests/npm/spec/tests/codedJsonTests.js index f83765e8..6c28e279 100644 --- a/tests/npm/spec/tests/codedJsonTests.js +++ b/tests/npm/spec/tests/codedJsonTests.js @@ -3,8 +3,11 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); +/** Path to target.cjson */ const cjsonfilePath = path.join(__dirname, "..", "..", "..", "\\test-files\\target.cjson"); +/** Path to source.json */ const jsonfilePath = path.join(__dirname, "..", "..", "..", "\\test-files\\source.json"); +/** Path to pure.json */ const pureJsonfilePath = path.join(__dirname, "..", "..", "..", "\\test-files\\pure.json"); /** @@ -37,10 +40,22 @@ describe("CJSON Test 1", () => { /** * Tests related to native JSON files */ -describe("CJSON Test 2", () => { +describe("JSON Test 2", () => { it("I should be able to use isContentJson()", () => { var cjson = new Cjson(pureJsonfilePath); assert.equal(cjson.isContentJson(), true); }); + + it("I should be able to parse jpath using `obj< Cjson >.json.parse(\"Valid.JPATH\")`", () => { + var cjson = new Cjson(cjsonfilePath); + var value = cjson.json.parse("source.quiz.sport.q1.question"); + assert.equal(value, "Which one is correct team name in NBA?"); + }); + + it("I should be able to parse full json using `obj< Cjson >.json.parse()`", () => { + var cjson = new Cjson(cjsonfilePath); + var value = cjson.json.parse(); + assert.equal(value, cjson.deserialize()); + }); }); \ No newline at end of file