Weather App
 
Loading...
Searching...
No Matches
JSONTools.h
Go to the documentation of this file.
1
5
6 #pragma once
7 #ifndef JSONTOOLS_H
8 #define JSONTOOLS_H
9
10 #include <nlohmann/json.hpp>
11 #include <string>
12 #include <algorithm>
13
19 float JSON_ParseNumber(const nlohmann::json& item);
20
27 float JSON_ParseNumber(const nlohmann::json& item, const std::string keyName);
28
34 std::string JSON_ParseString(const nlohmann::json& item);
35
42 std::string JSON_ParseString(const nlohmann::json& item, const std::string keyName);
43
49 std::string JSON_ParseAsString(const nlohmann::json& item);
50
57 std::string JSON_ParseAsString(const nlohmann::json& item, const std::string keyName);
58
64 bool JSON_isNumber(const nlohmann::json& item);
65
72 bool JSON_isNumber(const nlohmann::json& item, const std::string keyName);
73
80 bool JSON_FromFile(nlohmann::json& data, std::string targetFile);
81
88 bool JSON_ToFile(nlohmann::json& data, std::string targetFile);
89
95 void JSON_Unique(nlohmann::json& jsonArray, const std::string& key);
96
104 size_t JSON_Find(const std::string& keyValueDumped, const std::string& keyName, const nlohmann::json& arr);
105
112 void JSON_UpdateArray(nlohmann::json& present, const nlohmann::json& fetched, const std::string& uniqueKeyName);
113
120 bool parseDateTime(const std::string& datetime, std::tm& tm);
121
122 #endif // JSONTOOLS_H
bool JSON_isNumber(const nlohmann::json &item)
Checks if a JSON item is a number.
std::string JSON_ParseAsString(const nlohmann::json &item)
Converts a JSON item into a string representation.
bool JSON_ToFile(nlohmann::json &data, std::string targetFile)
Saves JSON data to a file.
size_t JSON_Find(const std::string &keyValueDumped, const std::string &keyName, const nlohmann::json &arr)
Finds the index of an object in a JSON array based on a key-value pair.
void JSON_UpdateArray(nlohmann::json &present, const nlohmann::json &fetched, const std::string &uniqueKeyName)
Updates an existing JSON array by merging elements based on a unique key.
void JSON_Unique(nlohmann::json &jsonArray, const std::string &key)
Removes duplicate entries in a JSON array based on a unique key.
bool parseDateTime(const std::string &datetime, std::tm &tm)
Parses a date-time string into a tm structure.
bool JSON_FromFile(nlohmann::json &data, std::string targetFile)
Loads JSON data from a file.
std::string JSON_ParseString(const nlohmann::json &item)
Parses a string from a JSON item.
float JSON_ParseNumber(const nlohmann::json &item)
Parses a number from a JSON item.