├── .gitignore
├── CMakeLists.txt
├── Dockerfile.alpine
├── Dockerfile.debian
├── LICENSE
├── README.md
├── clang-format.bash
├── ext
├── argparse
│ └── argparse.hpp
├── catch2
│ └── catch.hpp
└── termcolor
│ └── termcolor.hpp
├── img
├── 01.png
├── 02.png
├── 03.png
├── 04.png
└── logo.png
├── include
└── jsonlint
│ ├── errors.hpp
│ ├── lexer.hpp
│ ├── parser.hpp
│ ├── string.hpp
│ └── utf8.hpp
├── src
├── errors.cpp
├── lexer.cpp
├── main.cpp
├── parser.cpp
└── string.cpp
└── test
├── lexer
├── keywords.cpp
├── number.cpp
├── punctuation.cpp
├── string.cpp
└── whitespace.cpp
├── main.cpp
└── parser
├── array.cpp
├── number.cpp
├── object.cpp
└── string.cpp
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | .vscode/
28 | # Uncomment if you have tasks that create the project's static files in wwwroot
29 | #wwwroot/
30 |
31 | # MSTest test Results
32 | [Tt]est[Rr]esult*/
33 | [Bb]uild[Ll]og.*
34 |
35 | # NUNIT
36 | *.VisualState.xml
37 | TestResult.xml
38 |
39 | # Build Results of an ATL Project
40 | [Dd]ebugPS/
41 | [Rr]eleasePS/
42 | dlldata.c
43 |
44 | # DNX
45 | project.lock.json
46 | project.fragment.lock.json
47 | artifacts/
48 |
49 | *_i.c
50 | *_p.c
51 | *_i.h
52 | *.ilk
53 | *.meta
54 | *.obj
55 | *.pch
56 | *.pdb
57 | *.pgc
58 | *.pgd
59 | *.rsp
60 | *.sbr
61 | *.tlb
62 | *.tli
63 | *.tlh
64 | *.tmp
65 | *.tmp_proj
66 | *.log
67 | *.vspscc
68 | *.vssscc
69 | .builds
70 | *.pidb
71 | *.svclog
72 | *.scc
73 |
74 | # Chutzpah Test files
75 | _Chutzpah*
76 |
77 | # Visual C++ cache files
78 | ipch/
79 | *.aps
80 | *.ncb
81 | *.opendb
82 | *.opensdf
83 | *.sdf
84 | *.cachefile
85 | *.VC.db
86 | *.VC.VC.opendb
87 |
88 | # Visual Studio profiler
89 | *.psess
90 | *.vsp
91 | *.vspx
92 | *.sap
93 |
94 | # TFS 2012 Local Workspace
95 | $tf/
96 |
97 | # Guidance Automation Toolkit
98 | *.gpState
99 |
100 | # ReSharper is a .NET coding add-in
101 | _ReSharper*/
102 | *.[Rr]e[Ss]harper
103 | *.DotSettings.user
104 |
105 | # JustCode is a .NET coding add-in
106 | .JustCode
107 |
108 | # TeamCity is a build add-in
109 | _TeamCity*
110 |
111 | # DotCover is a Code Coverage Tool
112 | *.dotCover
113 |
114 | # NCrunch
115 | _NCrunch_*
116 | .*crunch*.local.xml
117 | nCrunchTemp_*
118 |
119 | # MightyMoose
120 | *.mm.*
121 | AutoTest.Net/
122 |
123 | # Web workbench (sass)
124 | .sass-cache/
125 |
126 | # Installshield output folder
127 | [Ee]xpress/
128 |
129 | # DocProject is a documentation generator add-in
130 | DocProject/buildhelp/
131 | DocProject/Help/*.HxT
132 | DocProject/Help/*.HxC
133 | DocProject/Help/*.hhc
134 | DocProject/Help/*.hhk
135 | DocProject/Help/*.hhp
136 | DocProject/Help/Html2
137 | DocProject/Help/html
138 |
139 | # Click-Once directory
140 | publish/
141 |
142 | # Publish Web Output
143 | *.[Pp]ublish.xml
144 | *.azurePubxml
145 | # TODO: Comment the next line if you want to checkin your web deploy settings
146 | # but database connection strings (with potential passwords) will be unencrypted
147 | #*.pubxml
148 | *.publishproj
149 |
150 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
151 | # checkin your Azure Web App publish settings, but sensitive information contained
152 | # in these scripts will be unencrypted
153 | PublishScripts/
154 |
155 | # NuGet Packages
156 | *.nupkg
157 | # The packages folder can be ignored because of Package Restore
158 | **/packages/*
159 | # except build/, which is used as an MSBuild target.
160 | !**/packages/build/
161 | # Uncomment if necessary however generally it will be regenerated when needed
162 | #!**/packages/repositories.config
163 | # NuGet v3's project.json files produces more ignoreable files
164 | *.nuget.props
165 | *.nuget.targets
166 |
167 | # Microsoft Azure Build Output
168 | csx/
169 | *.build.csdef
170 |
171 | # Microsoft Azure Emulator
172 | ecf/
173 | rcf/
174 |
175 | # Windows Store app package directories and files
176 | AppPackages/
177 | BundleArtifacts/
178 | Package.StoreAssociation.xml
179 | _pkginfo.txt
180 |
181 | # Visual Studio cache files
182 | # files ending in .cache can be ignored
183 | *.[Cc]ache
184 | # but keep track of directories ending in .cache
185 | !*.[Cc]ache/
186 |
187 | # Others
188 | ClientBin/
189 | ~$*
190 | *~
191 | *.dbmdl
192 | *.dbproj.schemaview
193 | *.jfm
194 | *.pfx
195 | *.publishsettings
196 | node_modules/
197 | orleans.codegen.cs
198 |
199 | # Since there are multiple workflows, uncomment next line to ignore bower_components
200 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
201 | #bower_components/
202 |
203 | # RIA/Silverlight projects
204 | Generated_Code/
205 |
206 | # Backup & report files from converting an old project file
207 | # to a newer Visual Studio version. Backup files are not needed,
208 | # because we have git ;-)
209 | _UpgradeReport_Files/
210 | Backup*/
211 | UpgradeLog*.XML
212 | UpgradeLog*.htm
213 |
214 | # SQL Server files
215 | *.mdf
216 | *.ldf
217 |
218 | # Business Intelligence projects
219 | *.rdl.data
220 | *.bim.layout
221 | *.bim_*.settings
222 |
223 | # Microsoft Fakes
224 | FakesAssemblies/
225 |
226 | # GhostDoc plugin setting file
227 | *.GhostDoc.xml
228 |
229 | # Node.js Tools for Visual Studio
230 | .ntvs_analysis.dat
231 |
232 | # Visual Studio 6 build log
233 | *.plg
234 |
235 | # Visual Studio 6 workspace options file
236 | *.opt
237 |
238 | # Visual Studio LightSwitch build output
239 | **/*.HTMLClient/GeneratedArtifacts
240 | **/*.DesktopClient/GeneratedArtifacts
241 | **/*.DesktopClient/ModelManifest.xml
242 | **/*.Server/GeneratedArtifacts
243 | **/*.Server/ModelManifest.xml
244 | _Pvt_Extensions
245 |
246 | # Paket dependency manager
247 | .paket/paket.exe
248 | paket-files/
249 |
250 | # FAKE - F# Make
251 | .fake/
252 |
253 | # JetBrains Rider
254 | .idea/
255 | *.sln.iml
256 |
257 | # CodeRush
258 | .cr/
259 |
260 | # Python Tools for Visual Studio (PTVS)
261 | __pycache__/
262 | *.pyc
263 |
264 | # CMake build directory
265 | build
266 |
267 | # Cppcheck build directory
268 | analysis-cppcheck-build-dir
269 |
270 | # Ideas directory
271 | ideas
272 |
273 | desktop.iniimages/
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.6)
2 | project(JSONLINT)
3 |
4 | if(NOT CMAKE_BUILD_TYPE)
5 | set(CMAKE_BUILD_TYPE Release)
6 | endif()
7 |
8 | # Disable deprecation for windows
9 | if (WIN32)
10 | add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
11 | endif()
12 |
13 | # UTILS library
14 | file(GLOB UTILS_SOURCES
15 | "src/string.cpp"
16 | "src/errors.cpp"
17 | )
18 | ADD_LIBRARY(UTILS STATIC ${UTILS_SOURCES})
19 | INCLUDE_DIRECTORIES("include")
20 | set_target_properties(UTILS PROPERTIES OUTPUT_NAME utils)
21 | TARGET_LINK_LIBRARIES(UTILS)
22 | set_property(TARGET UTILS PROPERTY CXX_STANDARD 17)
23 |
24 | # LEXER library
25 | file(GLOB LEXER_SOURCES
26 | "src/lexer.cpp"
27 | )
28 | ADD_LIBRARY(LEXER STATIC ${LEXER_SOURCES})
29 | INCLUDE_DIRECTORIES("include")
30 | set_target_properties(LEXER PROPERTIES OUTPUT_NAME lexer)
31 | TARGET_LINK_LIBRARIES(LEXER UTILS)
32 | set_property(TARGET LEXER PROPERTY CXX_STANDARD 17)
33 |
34 | # PARSER library
35 | file(GLOB PARSER_SOURCES
36 | "src/parser.cpp"
37 | )
38 | ADD_LIBRARY(PARSER STATIC ${PARSER_SOURCES})
39 | INCLUDE_DIRECTORIES("include" "ext")
40 | set_target_properties(PARSER PROPERTIES OUTPUT_NAME parser)
41 | TARGET_LINK_LIBRARIES(PARSER LEXER)
42 | set_property(TARGET PARSER PROPERTY CXX_STANDARD 17)
43 |
44 | # JSONLINT CLI
45 | file(GLOB JSONLINT_SOURCES
46 | "src/main.cpp"
47 | )
48 | ADD_EXECUTABLE(JSONLINT ${JSONLINT_SOURCES})
49 | INCLUDE_DIRECTORIES("include" "ext")
50 | set_target_properties(JSONLINT PROPERTIES OUTPUT_NAME jsonlint)
51 | TARGET_LINK_LIBRARIES(JSONLINT PARSER)
52 | set_property(TARGET JSONLINT PROPERTY CXX_STANDARD 17)
53 |
54 | # Tests
55 | file(GLOB TEST_SOURCES
56 | "test/*.cpp"
57 | "test/lexer/*.cpp"
58 | "test/parser/*.cpp"
59 | )
60 | ADD_EXECUTABLE(TESTS ${TEST_SOURCES})
61 | INCLUDE_DIRECTORIES("ext")
62 | set_target_properties(TESTS PROPERTIES OUTPUT_NAME tests)
63 | TARGET_LINK_LIBRARIES(TESTS PARSER)
64 | set_property(TARGET TESTS PROPERTY CXX_STANDARD 17)
65 |
66 | # make check - runs unit tests
67 | if (UNIX)
68 | add_custom_target(check COMMAND ./tests)
69 | endif(UNIX)
70 |
--------------------------------------------------------------------------------
/Dockerfile.alpine:
--------------------------------------------------------------------------------
1 | ARG BASE_IMAGE=alpine:latest
2 |
3 | FROM ${BASE_IMAGE} AS builder
4 |
5 | RUN apk update \
6 | && apk add git cmake make binutils musl-dev g++
7 |
8 | WORKDIR /build
9 |
10 | RUN git clone https://github.com/p-ranav/jsonlint.git
11 |
12 | WORKDIR /build/jsonlint/build
13 |
14 | RUN git rev-parse > git-revision
15 |
16 | RUN cmake .. \
17 | && make \
18 | && make check
19 |
20 | FROM ${BASE_IMAGE}
21 |
22 | RUN apk update \
23 | && apk add libgcc libstdc++
24 |
25 | WORKDIR /jsonlint
26 |
27 | COPY --from=builder /build/jsonlint/build/git-revision .
28 | COPY --from=builder /build/jsonlint/build/jsonlint .
29 |
--------------------------------------------------------------------------------
/Dockerfile.debian:
--------------------------------------------------------------------------------
1 | ARG BASE_IMAGE=debian:sid-slim
2 |
3 | FROM ${BASE_IMAGE} AS builder
4 |
5 | RUN apt-get update \
6 | && apt-get install -y --no-install-recommends ca-certificates git cmake make clang
7 |
8 | WORKDIR /build
9 |
10 | RUN git clone https://github.com/p-ranav/jsonlint.git
11 |
12 | WORKDIR /build/jsonlint/build
13 |
14 | RUN git rev-parse > git-revision
15 |
16 | RUN cmake .. \
17 | && make \
18 | && make check
19 |
20 | FROM ${BASE_IMAGE}
21 |
22 | WORKDIR /jsonlint
23 |
24 | COPY --from=builder /build/jsonlint/build/git-revision .
25 | COPY --from=builder /build/jsonlint/build/jsonlint .
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Pranav Srinivas Kumar
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | `jsonlint` is a lightweight command-line tool for validating JSON.
6 |
7 | ## Building `jsonlint`
8 |
9 | ```bash
10 | $ git clone https://github.com/p-ranav/jsonlint.git
11 | $ cd jsonlint
12 | $ mkdir build && cd build
13 | $ cmake .. && make && make check
14 | ```
15 |
16 | ## Usage
17 |
18 | ```bash
19 | $ ./jsonlint --help
20 | Usage: jsonlint [options] file
21 |
22 | Positional arguments:
23 | file json file to validate
24 |
25 | Optional arguments:
26 | -h --help show this help message and exit
27 | ```
28 |
29 | ## Example Scenarios
30 |
31 | ### Unterminated String
32 |
33 |
34 |
35 | ### Trailing comma in array
36 |
37 |
38 |
39 | ### Duplicate key in object
40 |
41 |
42 |
43 | ### Typo in keyword
44 |
45 |
46 |
--------------------------------------------------------------------------------
/clang-format.bash:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | find ./include ./src ./test/ -type f \( -iname \*.cpp -o -iname \*.hpp \) | xargs clang-format -style="{ColumnLimit : 100}" -i
3 |
--------------------------------------------------------------------------------
/ext/argparse/argparse.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | __ _ _ __ __ _ _ __ __ _ _ __ ___ ___
3 | / _` | '__/ _` | '_ \ / _` | '__/ __|/ _ \ Argument Parser for Modern C++
4 | | (_| | | | (_| | |_) | (_| | | \__ \ __/ http://github.com/p-ranav/argparse
5 | \__,_|_| \__, | .__/ \__,_|_| |___/\___|
6 | |___/|_|
7 |
8 | Licensed under the MIT License .
9 | SPDX-License-Identifier: MIT
10 | Copyright (c) 2019 Pranav Srinivas Kumar .
11 |
12 | Permission is hereby granted, free of charge, to any person obtaining a copy
13 | of this software and associated documentation files (the "Software"), to deal
14 | in the Software without restriction, including without limitation the rights
15 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 | copies of the Software, and to permit persons to whom the Software is
17 | furnished to do so, subject to the following conditions:
18 |
19 | The above copyright notice and this permission notice shall be included in all
20 | copies or substantial portions of the Software.
21 |
22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 | SOFTWARE.
29 | */
30 | #pragma once
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include