Welcome › Forums › General PowerShell Q&A › Powershell 7 TEST-JSON
- This topic has 1 reply, 2 voices, and was last updated 4 months, 3 weeks ago by
Participant.
Viewing 1 reply thread
-
AuthorPosts
-
-
August 23, 2020 at 8:57 am #251993
The Test-Json module does not validate a valid Json.
Take a look at this Json, it’s validated from jsonlint but in powershell I get Cannot parse the JSONPowerShell123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104{"name": "json-server","version": "0.16.1","description": "Get a full fake REST API with zero coding in less than 30 seconds","main": "./lib/server/index.js","bin": "./lib/cli/bin.js","scripts": {"test": "npm run build && cross-env NODE_ENV=test jest && npm run lint","start": "babel-node -- src/cli/bin db.json -r routes.json","lint": "eslint . --ignore-path .gitignore","fix": "npm run lint -- --fix","build": "babel src -d lib","toc": "markdown-toc -i README.md","postversion": "git push && git push --tags","prepublishOnly": "npm test && npm run build && pkg-ok"},"dependencies": {"body-parser": "^1.19.0","chalk": "^3.0.0","compression": "^1.7.4","connect-pause": "^0.1.1","cors": "^2.8.5","errorhandler": "^1.5.1","express": "^4.17.1","express-urlrewrite": "^1.2.0","json-parse-helpfulerror": "^1.0.3","lodash": "^4.17.15","lodash-id": "^0.14.0","lowdb": "^1.0.0","method-override": "^3.0.0","morgan": "^1.9.1","nanoid": "^2.1.11","please-upgrade-node": "^3.2.0","pluralize": "^8.0.0","request": "^2.88.2","server-destroy": "^1.0.1","update-notifier": "^4.0.0","yargs": "^15.1.0"},"devDependencies": {"@babel/cli": "^7.8.4","@babel/core": "^7.8.4","@babel/node": "^7.8.4","@babel/preset-env": "^7.8.4","cross-env": "^7.0.0","eslint": "^6.8.0","eslint-config-prettier": "^6.10.0","eslint-config-standard": "^14.1.0","eslint-plugin-import": "^2.20.1","eslint-plugin-node": "^11.0.0","eslint-plugin-prettier": "^3.1.2","eslint-plugin-promise": "^4.2.1","eslint-plugin-standard": "^4.0.1","husky": "^4.2.1","jest": "^25.1.0","markdown-toc": "^1.2.0","mkdirp": "^1.0.3","npm-run-all": "^4.1.5","os-tmpdir": "^2.0.0","pkg-ok": "^2.3.1","prettier": "^1.19.1","rimraf": "^3.0.2","server-ready": "^0.3.1","supertest": "^4.0.2","temp-write": "^4.0.0"},"repository": {"type": "git","url": "git://github.com/typicode/json-server.git"},"keywords": ["JSON","server","fake","REST","API","prototyping","mock","mocking","test","testing","rest","data","dummy","sandbox"],"license": "MIT","bugs": {"url": "https://github.com/typicode/json-server/issues"},"homepage": "https://github.com/typicode/json-server","engines": {"node": ">=10"},"husky": {"hooks": {"pre-commit": "npm test"}},"jest": {"testURL": "http://localhost/"}}-
This topic was modified 4 months, 3 weeks ago by
kvprasoon. Reason: Code formatting and moving to proper forum
-
This topic was modified 4 months, 3 weeks ago by
-
August 24, 2020 at 11:16 am #252146
Not familiar with Test-Json, but an option would be to just attempt a parse like this:
PowerShell123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114$json = @"{"name": "json-server","version": "0.16.1","description": "Get a full fake REST API with zero coding in less than 30 seconds","main": "./lib/server/index.js","bin": "./lib/cli/bin.js","scripts": {"test": "npm run build && cross-env NODE_ENV=test jest && npm run lint","start": "babel-node -- src/cli/bin db.json -r routes.json","lint": "eslint . --ignore-path .gitignore","fix": "npm run lint -- --fix","build": "babel src -d lib","toc": "markdown-toc -i README.md","postversion": "git push && git push --tags","prepublishOnly": "npm test && npm run build && pkg-ok"},"dependencies": {"body-parser": "^1.19.0","chalk": "^3.0.0","compression": "^1.7.4","connect-pause": "^0.1.1","cors": "^2.8.5","errorhandler": "^1.5.1","express": "^4.17.1","express-urlrewrite": "^1.2.0","json-parse-helpfulerror": "^1.0.3","lodash": "^4.17.15","lodash-id": "^0.14.0","lowdb": "^1.0.0","method-override": "^3.0.0","morgan": "^1.9.1","nanoid": "^2.1.11","please-upgrade-node": "^3.2.0","pluralize": "^8.0.0","request": "^2.88.2","server-destroy": "^1.0.1","update-notifier": "^4.0.0","yargs": "^15.1.0"},"devDependencies": {"@babel/cli": "^7.8.4","@babel/core": "^7.8.4","@babel/node": "^7.8.4","@babel/preset-env": "^7.8.4","cross-env": "^7.0.0","eslint": "^6.8.0","eslint-config-prettier": "^6.10.0","eslint-config-standard": "^14.1.0","eslint-plugin-import": "^2.20.1","eslint-plugin-node": "^11.0.0","eslint-plugin-prettier": "^3.1.2","eslint-plugin-promise": "^4.2.1","eslint-plugin-standard": "^4.0.1","husky": "^4.2.1","jest": "^25.1.0","markdown-toc": "^1.2.0","mkdirp": "^1.0.3","npm-run-all": "^4.1.5","os-tmpdir": "^2.0.0","pkg-ok": "^2.3.1","prettier": "^1.19.1","rimraf": "^3.0.2","server-ready": "^0.3.1","supertest": "^4.0.2","temp-write": "^4.0.0"},"repository": {"type": "git","url": "git://github.com/typicode/json-server.git"},"keywords": ["JSON","server","fake","REST","API","prototyping","mock","mocking","test","testing","rest","data","dummy","sandbox"],"author": "Typicode <typicode@gmail.com>","license": "MIT","bugs": {"url": "https://github.com/typicode/json-server/issues"},"homepage": "https://github.com/typicode/json-server","engines": {"node": ">=10"},"husky": {"hooks": {"pre-commit": "npm test"}},"jest": {"testURL": "http://localhost/"}}"@try {$parsedJson = $json | ConvertFrom-Json -ErrorAction Stop}catch {'Invalid JSON'}This uses the built-in JSON parser to attempt to create a valid object in Powershell. If you want to use Test-Json, you’ll have to reach out to the module creator and work with them on any bug.
-
-
AuthorPosts
Viewing 1 reply thread
- The topic ‘Powershell 7 TEST-JSON’ is closed to new replies.