{"id":13734306,"url":"https://github.com/timo/json_fast","last_synced_at":"2025-10-25T16:30:35.264Z","repository":{"id":29899396,"uuid":"33445059","full_name":"timo/json_fast","owner":"timo","description":"a naive imperative json parser in perl6, to evaluate performance against JSON::Tiny","archived":false,"fork":false,"pushed_at":"2023-05-10T15:04:24.000Z","size":231,"stargazers_count":27,"open_issues_count":13,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-31T07:51:27.704Z","etag":null,"topics":["json","perl6"],"latest_commit_sha":null,"homepage":null,"language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timo.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-04-05T15:23:30.000Z","updated_at":"2024-09-26T18:54:23.000Z","dependencies_parsed_at":"2024-01-12T02:14:06.026Z","dependency_job_id":null,"html_url":"https://github.com/timo/json_fast","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timo%2Fjson_fast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timo%2Fjson_fast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timo%2Fjson_fast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timo%2Fjson_fast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timo","download_url":"https://codeload.github.com/timo/json_fast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238174095,"owners_count":19428624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","perl6"],"created_at":"2024-08-03T03:00:54.489Z","updated_at":"2025-10-25T16:30:34.819Z","avatar_url":"https://github.com/timo.png","language":"Raku","funding_links":[],"categories":["Modules"],"sub_categories":["Catalogue"],"readme":"[![Build Status](https://travis-ci.org/timo/json_fast.svg?branch=master)](https://travis-ci.org/timo/json_fast)\n\nJSON::Fast\n==========\n\nA naive imperative JSON parser in pure Raku (but with direct access to `nqp::` ops), to evaluate performance against `JSON::Tiny`. It is a drop-in replacement for `JSON::Tiny`’s from-json and to-json subs, but it offers a few extra features.\n\nCurrently it seems to be about 4x faster and uses up about a quarter of the RAM JSON::Tiny would use.\n\nThis module also includes a very fast to-json function that tony-o created and lizmat later completely refactored.\n\nSYNOPSIS\n--------\n\n        use JSON::Fast;\n        my $storage-path = $*SPEC.tmpdir.child(\"json-fast-example-$*PID.json\");\n        say \"using path $storage-path for example\";\n        for \u003crecreatable monascidian spectrograph bardiest ayins sufi lavanga Dachia\u003e -\u003e $word {\n            say \"- loading json file\";\n            my $current-data = from-json ($storage-path.IO.slurp // \"\\{}\");\n            # $current-data now contains a Hash object populated with what was in the file\n            # (or an empty hash in the very first step when the file didn't exsit yet)\n\n            say \"- adding entry for $word\";\n            $current-data{$word}{\"length\"} = $word.chars;\n            $current-data{$word}{\"first letter\"} = $word.substr(0,1);\n\n            say \"- saving json file\";\n            $storage-path.IO.spurt(to-json $current-data);\n            # to-json gives us a regular string, so we can plop that\n            # into the file with the spurt method\n\n            say \"json file is now $storage-path.IO.s() bytes big\";\n            say \"===\";\n        }\n        say \"here is the entire contents of the json file:\";\n        say \"====\";\n        say $storage-path.IO.slurp();\n        say \"====\";\n        say \"deleting storage file ...\";\n        $storage-path.IO.unlink;\n\nExported subroutines\n--------------------\n\n### to-json\n\n        my $*JSON_NAN_INF_SUPPORT = 1; # allow NaN, Inf, and -Inf to be serialized.\n        say to-json [\u003cmy Raku data structure\u003e];\n        say to-json [\u003cmy Raku data structure\u003e], :!pretty;\n        say to-json [\u003cmy Raku data structure\u003e], :spacing(4);\n\n        enum Blerp \u003cHello Goodbye\u003e;\n        say to-json [Hello, Goodbye]; # [\"Hello\", \"Goodbye\"]\n        say to-json [Hello, Goodbye], :enums-as-value; # [0, 1]\n\nEncode a Raku data structure into JSON. Takes one positional argument, which is a thing you want to encode into JSON. Takes these optional named arguments:\n\n#### pretty\n\n`Bool`. Defaults to `True`. Specifies whether the output should be \"pretty\", human-readable JSON. When set to `False`, will output json in a single line.\n\n#### spacing\n\n`Int`. Defaults to `2`. Applies only when `pretty` is `True`. Controls how much spacing there is between each nested level of the output.\n\n#### sorted-keys\n\nSpecifies whether keys from objects should be sorted before serializing them to a string or if `$obj.keys` is good enough. Defaults to `False`. Can also be specified as a `Callable` with the same type of argument that the `.sort` method accepts to provide alternate sorting methods.\n\n#### enum-as-value\n\n`Bool`, defaults to `False`. Specifies whether `enum`s should be json-ified as their underlying values, instead of as the name of the `enum`.\n\n### from-json\n\n        my $x = from-json '[\"foo\", \"bar\", {\"ber\": \"bor\"}]';\n        say $x.perl;\n        # outputs: $[\"foo\", \"bar\", {:ber(\"bor\")}]\n\nTakes one positional argument that is coerced into a `Str` type and represents a JSON text to decode. Returns a Raku datastructure representing that JSON.\n\n#### immutable\n\n`Bool`. Defaults to `False`. Specifies whether `Hash`es and `Array`s should be rendered as immutable datastructures instead (as `Map` / `List`. Creating an immutable data structures is mostly saving on memory usage, and a little bit on CPU (typically around 5%).\n\nThis also has the side effect that elements from the returned structure can now be iterated over directly because they are not containerized.\n\n        my %hash := from-json \"META6.json\".IO.slurp, :immutable;\n        say \"Provides:\";\n        .say for %hash\u003cprovides\u003e;\n\n#### allow-jsonc\n\n`Bool`. Defaults to `False`. Specifies whether commmands adhering to the [JSONC standard](https://changelog.com/news/jsonc-is-a-superset-of-json-which-supports-comments-6LwR) are allowed.\n\nAdditional features\n-------------------\n\n### Adapting defaults of \"from-json\"\n\nIn the `use` statement, you can add the string `\"immutable\"` to make the default of the `immutable` parameter to the `from-json` subroutine `True`, rather than `False`.\n\n        use JSON::Fast \u003cimmutable\u003e;  # create immutable data structures by default\n\n### Adapting defaults of \"to-json\"\n\nIn the `use` statement, you can add the strings `\"!pretty\"`, `\"sorted-keys\"` and/or `\"enums-as-value\"` to change the associated defaults of the `to-json` subroutine.\n\n        use JSON::FAST \u003c!pretty sorted-keys enums-as-value\u003e;\n\n### Strings containing multiple json pieces\n\nWhen the document contains additional non-whitespace after the first successfully parsed JSON object, JSON::Fast will throw the exception `X::JSON::AdditionalContent`. If you expect multiple objects, you can catch that exception, retrieve the parse result from its `parsed` attribute, and remove the first `rest-position` characters off of the string and restart parsing from there.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimo%2Fjson_fast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimo%2Fjson_fast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimo%2Fjson_fast/lists"}