summaryrefslogtreecommitdiff
path: root/AK/JsonObject.h
AgeCommit message (Collapse)Author
2021-06-29AK: Use [[nodiscard]] in JsonObject and JsonArrayMax Wipfli
2021-06-29AK+Spreadsheet+LibWeb: Remove JsonObject::get_or()Max Wipfli
This removes JsonObject::get_or(), which is inefficient because it has to copy the returned value. It was only used in a few cases, some of which resulted in copying JsonObjects, which can become quite large.
2021-06-29AK: Add JsonObject::has_* methodsMax Wipfli
This adds methods to JsonObject to check if a key exists with a certain type. This simplifies code that validates whether a JsonObject has the expected structure.
2021-06-29AK+Everywhere: Change int to size_t in JsonObject and JsonArrayMax Wipfli
2021-06-29AK: Return const& from JsonObject::get()Max Wipfli
This adds a static JsonValue* s_null_value, which allows JsonObject::get to return a reference instaed of copying the return value. Since JsonValue is only 16 bytes, this seems like a reasonable compromise.
2021-06-29AK: Use OrderedHashMap in JsonObjectMax Wipfli
This changes JsonObject to use the new OrderedHashMap instead of an extra vector for tracking the insertion order. This also adds a default value for the KeyTraits template argument in OrderedHashMap. Furthermore, it fixes two cases where code iterating over a JsonObject relied on the value argument being copied before invoking the callback.
2021-06-29AK: Use east const style in Json{Array,Object}.hMax Wipfli
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-08AK: JsonObject::value_or() fallback value should be a const referenceAndreas Kling
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-09AK: Use StringBuilder::appendff() instead of appendf()Andreas Kling
2021-02-08Everywhere: Remove unnecessary headers 2/4Ben Wiederhake
Arbitrarily split up to make git bisect easier. These unnecessary #include's were found by combining an automated tool (which determined likely candidates) and some brain power (which decided whether the #include is also semantically superfluous).
2021-01-12AK: Simplify constructors and conversions from nullptr_tLenny Maiorani
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.
2020-11-02AK+Kernel: Escape JSON keys & valuesAndreas Kling
Grab the escaping logic from JSON string value serialization and use it for serializing all keys and values. Fixes #3917.
2020-10-08AK: Use new format functions.asynts
2020-09-25Meta+AK: Make clang-format-10 cleanBen Wiederhake
2020-09-06AK: Add JsonObject::remove()Andreas Kling
2020-08-10AK: Don't keep equal JsonObject keys in the order vector twiceLinus Groh
Fixes #3069.
2020-06-13AK: JsonParser improvementsMatthew Olsson
- Parsing invalid JSON no longer asserts Instead of asserting when coming across malformed JSON, JsonParser::parse now returns an Optional<JsonValue>. - Disallow trailing commas in JSON objects and arrays - No longer parse 'undefined', as that is a purely JS thing - No longer allow non-whitespace after anything consumed by the initial parse() call. Examples of things that were valid and no longer are: - undefineddfz - {"foo": 1}abcd - [1,2,3]4 - JsonObject.for_each_member now iterates in original insertion order
2020-06-03AK: JSON, Escape spacial character in string serializationHüseyin ASLITÜRK
2020-05-16Kernel: Absorb LibBareMetal back into the kernelAndreas Kling
This was supposed to be the foundation for some kind of pre-kernel environment, but nobody is working on it right now, so let's move everything back into the kernel and remove all the confusion.
2020-03-24AK: Add get_or() method to JsonObjectEmanuel Sprung
This allows to retrieve a default value for items thare are not available in the json object.
2020-03-06AK: Simplify JsonObject and JsonArray API a little bitAndreas Kling
Instead of set(const JsonValue&) and set(JsonValue&&), just do set(JsonValue) and let callers move() if they want. This removes some ambiguity and the compiler is smart enough to optimize it anyway.
2020-02-09AK: Apply changes for the Bootstrapper environmentLiav A
2020-02-06AK: Add some missing "inline" keywords in JsonObject.hAndreas Kling
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-12-30AK: Add JsonObject::get_ptr() for copy-free lookupAndreas Kling
This variant of get() returns a const JsonValue* instead of a JsonValue and can be used when you want to peek into a JsonObject's member fields without making copies.
2019-10-29AK: Allow JsonValue to store 64-bit integers internallyAndreas Kling
Add dedicated internal types for Int64 and UnsignedInt64. This makes it a bit more straightforward to work with 64-bit numbers (instead of just implicitly storing them as doubles.)
2019-10-21JsonObject: Add JsonObject::has(key)Andreas Kling
2019-09-06AK: Rename <AK/AKString.h> to <AK/String.h>Andreas Kling
This was a workaround to be able to build on case-insensitive file systems where it might get confused about <string.h> vs <String.h>. Let's just not support building that way, so String.h can have an objectively nicer name. :^)
2019-08-27JSON: Port JsonArray and JsonObject serialization to serializersSergey Bugaev
This way, primitive JsonValue serialization is still handled by JsonValue::serialize(), but JsonArray and JsonObject serialization always goes through serializer classes. This is no less efficient if you have the whole JSON in memory already.
2019-08-07JSON: Templatize the JSON serialization codeAndreas Kling
This makes it possible to use something other than a StringBuilder for serialization (and to produce something other than a String.) :^)
2019-08-04Json: Add efficient copy and move constructors for Json{Array,Object}Andreas Kling
This helps avoid copying JsonValues during parsing.
2019-07-08AK: Add JsonObject::set(key, &&value) overload.Andreas Kling
This dodges a whole bunch of value copying in JsonParser.
2019-06-24JsonObject: Let the compiler generate a copy constructor.Andreas Kling
This was only needed while HashMap was noncopyable. :^)
2019-06-18AK: Rename JsonObject::to_string() and pals to serialized().Andreas Kling
And the variant that serializes into a StringBuilder is called serialize().
2019-06-17AK: Use a single StringBuilder throughout JSON serialization.Andreas Kling
2019-06-17AK: Add some classes for JSON encoding.Andreas Kling
This patch adds JsonValue, JsonObject and JsonArray. You can use them to build up a JsonObject and then serialize it to a string via to_string(). This patch only implements encoding, no decoding yet.