-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
cmake_minimum_required(VERSION 3.26) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
project(json-beautifier VERSION 1.0 DESCRIPTION "A lightweight implementation of JSON Data Interchance Standard for C++ programming language.") | ||
|
||
add_executable(json-beautifier | ||
main.cpp | ||
) | ||
|
||
# Add JSONC Dependency | ||
|
||
include(FetchContent) | ||
|
||
FetchContent_Declare( | ||
JSONC | ||
GIT_REPOSITORY git@github.com:st235/JSONC.git | ||
GIT_TAG "main" | ||
GIT_SHALLOW TRUE | ||
GIT_PROGRESS ON | ||
) | ||
FetchContent_MakeAvailable(JSONC) | ||
|
||
target_link_libraries(json-beautifier jsonc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"_id":"667808619dc80527e5d96754","index":0,"guid":"cc6b18fb-c7b7-40f4-9a5c-54bced9196e3","isActive":false,"balance":"$3,203.77","picture":"http://placehold.it/32x32","age":34,"eyeColor":"green","name":"Faith Sherman","gender":"female","company":"MEDMEX","email":"faithsherman@medmex.com","phone":"+1 (944) 446-3807","address":"303 Oak Street, Taft, Louisiana, 6082","about":"Aliqua in nulla veniam occaecat. Ullamco labore sit laboris commodo aliquip dolore mollit sit qui laboris ullamco eu. Do culpa nisi incididunt excepteur elit mollit amet. Sint adipisicing consequat exercitation consectetur est aute. Fugiat consectetur laborum voluptate nostrud veniam do id amet. Nostrud ut exercitation dolore esse est fugiat nulla id nulla cillum ipsum esse sint deserunt.\r\n","registered":"2015-06-01T05:08:07 -01:00","latitude":-0.230575,"longitude":-31.937633,"tags":["magna","nisi","irure","reprehenderit","mollit","dolor","laboris"],"friends":[{"id":0,"name":"Dodson Shannon"},{"id":1,"name":"Keller Noble"},{"id":2,"name":"Boyer Klein"}],"greeting":"Hello, Faith Sherman! You have 7 unread messages.","favoriteFruit":"apple"},{"_id":"667808619c1b0a89cfc7255f","index":1,"guid":"f2f6cdcc-c467-4e19-a912-3fcfb6eb06b6","isActive":false,"balance":"$1,599.48","picture":"http://placehold.it/32x32","age":36,"eyeColor":"green","name":"Rocha Mann","gender":"male","company":"BRAINQUIL","email":"rochamann@brainquil.com","phone":"+1 (928) 599-2253","address":"580 Banker Street, Hollins, Massachusetts, 6501","about":"Pariatur occaecat commodo est proident ad officia. Incididunt nulla ut ullamco officia nulla quis nostrud ut et qui id qui officia. Tempor fugiat dolore eiusmod pariatur tempor magna veniam adipisicing eu velit consequat. Ex duis cillum labore ut aliquip nostrud dolore et laboris culpa cupidatat. Mollit non pariatur aliqua nostrud amet ut et labore.\r\n","registered":"2023-02-03T07:22:53 -00:00","latitude":-2.592665,"longitude":157.705033,"tags":["proident","dolore","dolore","veniam","est","cupidatat","duis"],"friends":[{"id":0,"name":"Summers Cortez"},{"id":1,"name":"Boyd Bonner"},{"id":2,"name":"Cooley Wooten"}],"greeting":"Hello, Rocha Mann! You have 8 unread messages.","favoriteFruit":"strawberry"},{"_id":"66780861b8eddb0dc6d2a903","index":2,"guid":"3254706b-f52e-4a0a-8c50-daf78cd2d816","isActive":true,"balance":"$2,855.82","picture":"http://placehold.it/32x32","age":36,"eyeColor":"blue","name":"White Dawson","gender":"male","company":"MUSANPOLY","email":"whitedawson@musanpoly.com","phone":"+1 (811) 462-2273","address":"803 Visitation Place, Columbus, Pennsylvania, 7188","about":"Ex exercitation reprehenderit consequat qui pariatur adipisicing Lorem amet. Veniam nostrud veniam adipisicing duis sit anim veniam amet cupidatat id cupidatat nisi magna id. Dolor aliqua laborum elit laborum ullamco nulla id veniam.\r\n","registered":"2015-03-12T12:25:17 -00:00","latitude":-72.68099,"longitude":123.633895,"tags":["dolor","dolore","qui","non","ut","aliqua","aliqua"],"friends":[{"id":0,"name":"Christie Clayton"},{"id":1,"name":"Russell Stout"},{"id":2,"name":"Edna Maddox"}],"greeting":"Hello, White Dawson! You have 1 unread messages.","favoriteFruit":"banana"},{"_id":"66780861a14f483b3a7f7550","index":3,"guid":"1ff8c06d-6dec-4022-883a-c01ca2c9adaa","isActive":false,"balance":"$2,924.55","picture":"http://placehold.it/32x32","age":37,"eyeColor":"blue","name":"Kara Sykes","gender":"female","company":"QUILM","email":"karasykes@quilm.com","phone":"+1 (870) 487-3851","address":"515 Bragg Court, Sussex, Rhode Island, 9160","about":"Minim deserunt cillum voluptate adipisicing minim. Ullamco irure est tempor do est sunt ea dolor consectetur. Fugiat id culpa id ad elit non qui non commodo ipsum ut labore aute quis.\r\n","registered":"2020-12-01T06:08:57 -00:00","latitude":79.218403,"longitude":-57.095335,"tags":["pariatur","magna","qui","tempor","cupidatat","mollit","ipsum"],"friends":[{"id":0,"name":"Reid Castillo"},{"id":1,"name":"Rachelle Rodriguez"},{"id":2,"name":"Susana Carlson"}],"greeting":"Hello, Kara Sykes! You have 9 unread messages.","favoriteFruit":"banana"},{"_id":"66780861625e7855f629f55d","index":4,"guid":"f416546e-d386-4ed2-a12f-42fd11bf181d","isActive":false,"balance":"$2,999.15","picture":"http://placehold.it/32x32","age":29,"eyeColor":"green","name":"Shields Burt","gender":"male","company":"BILLMED","email":"shieldsburt@billmed.com","phone":"+1 (883) 576-3771","address":"246 Grand Street, Tuttle, Palau, 3726","about":"Cupidatat id culpa ipsum veniam cillum officia in excepteur sunt. Consectetur irure duis est mollit. Duis irure nulla dolor veniam veniam elit id ut magna nisi minim elit reprehenderit. Qui elit exercitation nisi qui nisi amet nisi culpa elit est nulla nulla pariatur. Amet dolor adipisicing cillum amet do nostrud quis officia. Officia veniam adipisicing elit laborum pariatur esse exercitation quis cillum quis nisi sunt.\r\n","registered":"2014-04-13T09:24:10 -01:00","latitude":14.694507,"longitude":-110.891549,"tags":["proident","et","esse","amet","sunt","eu","pariatur"],"friends":[{"id":0,"name":"Wade Cabrera"},{"id":1,"name":"Tracie Buckner"},{"id":2,"name":"Roseann Meadows"}],"greeting":"Hello, Shields Burt! You have 8 unread messages.","favoriteFruit":"strawberry"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <memory> | ||
|
||
#include "json.h" | ||
#include "json_beautifier.h" | ||
|
||
namespace { | ||
|
||
std::string ReadFile(const std::string& filename) { | ||
std::ifstream file_stream(filename); | ||
std::stringstream buffer; | ||
buffer << file_stream.rdbuf(); | ||
return buffer.str(); | ||
} | ||
|
||
} // namespace | ||
|
||
int main(int argc, char *argv[]) { | ||
if (argc != 2) { | ||
std::cout << "Json Beautifier expects a single json file," << std::endl | ||
<< "See the command below:" << std::endl | ||
<< "\tjson-beautifier [file.json]" << std::endl; | ||
return 0; | ||
} | ||
|
||
const auto& file_context = ReadFile(std::string(argv[1])); | ||
|
||
json::JsonBeautifier beautifier; | ||
const auto& json = json::FromJson(file_context); | ||
const auto& beautified_json = beautifier.beautify(json.get()); | ||
|
||
std::cout << beautified_json << std::endl; | ||
|
||
return 0; | ||
} |