CodeSampleX

示例

json 2.9.1: Read and write JSON in Ruby on an image with no C compiler, where oj cannot be installed, without the built-in json defaults changing the data

已验证示例 — gem json 2.9.1: Read and write JSON in Ruby on an image with no C compiler, where oj cannot be installed, without the built-in json defaults changing…

sha256:bec86395ce786b02c01ea89597d38d802ad97a4c997dc95aaa3f09e24aeeffe9

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
1
声明的环境 ruby 3 linux x64 ruby 3 ruby bundler

验证运行环境

环境 契约 阶段 运行日期
ruby 3 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · gem@1
2026-08-14
ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 FAIL compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS
CONTAINER_RUN · gem@1
2026-08-18

案例

HOW
目标
Read and write JSON in Ruby on an image with no C compiler, where oj cannot be installed, without the built-in json defaults changing the data
符号
  • JSON.parse
  • JSON.generate
  • JSON.pretty_generate
  • JSON.dump
  • JSON.load
  • JSON::State
  • JSON::GeneratorError
  • JSON::ParserError
  • JSON::Ext::Generator
  • Object#to_json
环境
ruby 3
创建时间
2026-08-14T13:05:58Z

契约

  1. assert JSON.parse hands back String keys at every depth while symbolize_names: true changes keys only and leaves String values alone
  2. assert generate accepts symbol keys, so a Hash keyed by symbols round trips into string keys and stops equalling itself
  3. assert a non-String key is stringified by generate, symbolize_names then yields :"1" rather than 1, and two keys that stringify alike are both written and then collapsed by the parser, last one winning
  4. assert JSON.generate and to_json emit the same bytes for an object whose to_json accepts the state
  5. assert what to_json receives is a JSON::State that only a direct call omits, and that an object which accepts the state and drops it comes out compact inside a pretty document that still parses equal
  6. assert an arity-zero to_json works only on a direct call and raises ArgumentError through JSON.generate or from inside any container, including via Hash#to_json
  7. assert the generator splices in whatever to_json returned without checking it, so an invalid fragment builds a document JSON.parse rejects
  8. assert an object with no to_json is emitted as its to_s in quotes, symbols included, and only strict: true turns that back into a JSON::GeneratorError
  9. assert JSON.generate refuses NaN and Infinity, to_json refuses them identically, allow_nan writes them, and JSON.parse rejects that output unless it is given allow_nan too
  10. assert JSON::GeneratorError and JSON::ParserError are both JSON::JSONError, so one rescue covers both directions
  11. assert JSON.dump defaults to allow_nan and writes a document JSON.parse cannot read while JSON.load can, and that JSON.load defaults to allow_blank so an empty string is nil where JSON.parse raises
  12. assert a 2**53+1 integer and a thirty digit integer survive a round trip exactly, while the same digits with a decimal point lose the low bit and regenerate in exponent form
  13. assert bigdecimal is not visible under bundler at all, and that decimal_class: String keeps every digit of a fraction while leaving integers as Integer
  14. assert JSON.pretty_generate parses equal to the compact output, preserves key order in both, keeps empty containers on one line and writes no trailing newline
  15. assert json is absent from the bundle yet answers as a default gem at the version the purl names, and that the parser and generator actually loaded are .so files under the interpreter's own archdir
  16. assert no compiler and no make are on PATH and that requiring oj is a LoadError

文件

  • Gemfile
  • Gemfile.lock
  • csx.json
  • src/json_ops.rb
  • test/contract.rb

下载源代码构件 (tar.gz)

原始种子者

anonymous