Skip to content

Consolidate JSON stringify dependencies#251890

Merged
legrego merged 15 commits intoelastic:mainfrom
legrego:dr/json-stringify
Feb 10, 2026
Merged

Consolidate JSON stringify dependencies#251890
legrego merged 15 commits intoelastic:mainfrom
legrego:dr/json-stringify

Conversation

@legrego
Copy link
Member

@legrego legrego commented Feb 5, 2026

Resolves #233194

Moves all JSON stringification under @kbn/std where we already had an existing stringification utility. This also consolidates the implementation to a single third-party dependency, instead of 3.

Important

Please test your UIs! Tests may not catch all regressions!

Consolidate JSON Stringification Dependencies

Background

The issue #233194 requests consolidating JSON stringification dependencies. After analysis:

Dependency Usages Purpose Action
json-stable-stringify 23 files Deterministic/sorted keys for hashing Replace with @kbn/std
json-stringify-safe 1 file Handle circular references Replace with @kbn/std
json-stringify-pretty-compact 2 files Pretty-print with max line length Replace with @kbn/std

Solution: Extend @kbn/std Package

Extend the existing @kbn/std package with new JSON stringify utilities, backed by safe-stable-stringify which handles both circular references AND deterministic ordering.

Why @kbn/std?

  • Already has related utilities: safeJsonParse, safeJsonStringify

  • Widely used core package for general utilities

  • Avoids creating a new single-purpose package

Files to Modify in @kbn/std

src/platform/packages/shared/kbn-std/
  ├── package.json              # Add safe-stable-stringify dependency
  ├── index.ts                  # Export new functions
  └── src/
      ├── safe_json_stringify.ts    # Enhance to handle circular refs
      ├── stable_stringify.ts       # NEW: Deterministic stringify
      └── pretty_compact_stringify.ts  # NEW: Pretty-print with max line length

Purpose: What is this dependency used for? Briefly explain its role in your changes.
This is used for both stable and safe JSON stringification. It was already included as a transitive dependency. This promotes it to a top-level dependency.

Justification: Why is adding this dependency the best approach?
It allows us to consolidate JSON stringification use cases down to a single dependency.

@legrego legrego marked this pull request as ready for review February 5, 2026 19:13
@legrego legrego requested review from a team as code owners February 5, 2026 19:13
@kibanamachine
Copy link
Contributor

Dependency Review Bot Analysis 🔍

Found 1 new third-party dependencies:

Package Version Vulnerabilities Health Score
safe-stable-stringify 2.5.0 🔴 C: 0, 🟠 H: 0, 🟡 M: 0, 🟢 L: 0 safe-stable-stringify

Self Checklist

To help with the review, please update the PR description to address the following points for each new third-party dependency listed above:

  • Purpose: What is this dependency used for? Briefly explain its role in your changes.
  • Justification: Why is adding this dependency the best approach?
  • Alternatives explored: Were other options considered (e.g., using existing internal libraries/utilities, implementing the functionality directly)? If so, why was this dependency chosen over them?
  • Existing dependencies: Does Kibana have a dependency providing similar functionality? If so, why is the new one preferred?

Thank you for providing this information!

Copy link
Contributor

@jbudz jbudz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/kbn-optimizer/src/optimizer/diff_cache_key.ts LGTM

Copy link
Contributor

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResponseOps changes LGTM

Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core changes LGTM

Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data Discovery changes LGTM 👍

Copy link
Contributor

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in ESO plugin, LGTM, thanks!

@weltenwort
Copy link
Member

/oblt-deploy

@weltenwort weltenwort self-requested a review February 6, 2026 10:22
Copy link
Member

@weltenwort weltenwort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obs-exploration changes LGTM

Copy link
Member

@sabarasaba sabarasaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kibana management changes lgtm

Copy link
Contributor

@markov00 markov00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, thanks @legrego
LGTM

@legrego
Copy link
Member Author

legrego commented Feb 9, 2026

@elasticmachine merge upstream

Copy link
Contributor

@rmyz rmyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obs presentation changes LGTM

Copy link
Contributor

@christineweng christineweng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cases changes LGTM, code review only

@legrego legrego enabled auto-merge (squash) February 9, 2026 15:54
Copy link
Contributor

@nikitaindik nikitaindik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a minor visual regression in our diff UI when reviewing. While the diff is still technically correct, it now looks noisier in cases where an empty array becomes non-empty, or vice versa.

Old implementation

Unified view screenshots Image
Split view screenshots Image

This PR

Unified view screenshots Image
Split view screenshots Image

Let me take another look at it tomorrow and get back to you. As a raw idea, I guess we could pre-process JSONs to expand "[]" to "[\n]".

Copy link
Contributor

@nikitaindik nikitaindik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@legrego I pushed a commit with the fix. The diff UI now looks same as before. Feel free to merge once it builds.

@legrego
Copy link
Member Author

legrego commented Feb 10, 2026

@nikitaindik I really appreciate the review and code changes. Thanks!

@legrego
Copy link
Member Author

legrego commented Feb 10, 2026

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

⏳ Build in-progress

  • Buildkite Build
  • Commit: b186e26
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-251890-b186e26e46a8

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #10 / Alerting alerts_as_data alerts as data delay should not recover alert if the activeCount did not reach the alertDelay threshold with AAD
  • [job] [logs] FTR Configs #71 / serverless observability UI - telemetry discover/observabilitySolution/context_awareness/telemetry telemetry context should set EBT context for telemetry events when logs data source profile and reset

History

@legrego legrego merged commit 0c9ebf5 into elastic:main Feb 10, 2026
18 checks passed
mbondyra added a commit to mbondyra/kibana that referenced this pull request Feb 10, 2026
* commit '7dcc1fe3c205d2de0c3ca3f65804f21de09013c3': (285 commits)
  Enrich kbn-check-saved-objects-cli README with CI and manual usage docs (elastic#252557)
  [Discover] Add feature flag to make ESQL the default query mode (elastic#252268)
  Add maskProps.headerZindexLocation above to inspect component flyout (elastic#252543)
  [Security Solution][Atack/Alerts] Flyout header: Assignees  (elastic#252190)
  Upgrade EUI to v112.3.0 (elastic#252315)
  [Fleet] Make save_knowledge_base async in streaming state machine (elastic#252328)
  Upgrade @smithy/config-resolver 4.3.0 → 4.4.6 (elastic#252457)
  [Lens as API] Add colorMapping support for XY charts (ES|QL data layers) (elastic#252051)
  [WorkplaceAI] Add Google Drive data source and connector (elastic#250677)
  [Scout] Move GlobalSearch FTR tests to Scout (elastic#252201)
  [EDR Workflows] Fix osquery pack results display when agent clock is skewed (elastic#251417)
  [Observability Onboarding] Apply integrations limit after dedup in parseIntegrationsTSV (elastic#252486)
  [Entity Analytics] Update `host.ip` aggregation to remove painless script (elastic#252426)
  Address `@elastic/eui/require-table-caption` lint violations across `@elastic/obs-presentation-team` files (elastic#251050)
  Consolidate JSON stringify dependencies (elastic#251890)
  [index mgmt] Use esql instead of query dsl to get the index count (elastic#252422)
  Add Usage API Plugin (elastic#252434)
  Cases All Templates page (elastic#250372)
  [Agent Builder] Default value for optional params in ESQL tools (elastic#238472)
  [Fleet] Add upgrade_details.metadata.reason to AgentResponseSchema (elastic#252485)
  ...
@legrego legrego deleted the dr/json-stringify branch February 10, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting chore ci:project-deploy-observability Create an Observability project dependency-reduction initiative to reduce the number of Kibana's third-party dependencies release_note:skip Skip the PR/issue when compiling release notes Team:obs-presentation Focus: APM UI, Infra UI, Hosts UI, Universal Profiling, Obs Overview and left Navigation Team:Security Platform Security: Auth, Users, Roles, Spaces, Audit Logging, etc t// v9.4.0