Join our Newsletter — 33% off our NHI Course

JsonIgnore

JsonIgnore is an attribute used to prevent a property from being serialized or deserialized by System.Text.Json. Security teams use it to keep tokens, hashes, session values, and other sensitive fields out of API responses, logs, and downstream systems that should never receive them.

Expanded Definition

JsonIgnore is a .NET serialization attribute that instructs System.Text.Json to omit a property from serialization, deserialization, or both, depending on how it is applied. In security terms, it is a data handling control, not an access control. That distinction matters: JsonIgnore does not secure the value at rest, encrypt the field, or prevent direct in-memory access. It only limits how the property moves through application boundaries.

For security teams, the practical value is reducing accidental exposure of tokens, session values, internal identifiers, hashes, and other sensitive fields when objects are converted into JSON for APIs, telemetry, or downstream integrations. Its use is especially relevant when application models contain mixed-trust data, where some fields are safe to return and others must never leave the service boundary. Microsoft’s guidance for ignoring properties during serialization shows that the attribute can apply to output, input, or both, which is why implementation details must be checked carefully.

Usage in the industry is still evolving because teams sometimes treat JsonIgnore as a privacy or authorization mechanism, when it is really a serialization safeguard that supports those goals indirectly. The most common misapplication is assuming a field marked with JsonIgnore is protected everywhere, which occurs when developers still log, persist, or manually copy the same value into other objects.

Examples and Use Cases

Implementing JsonIgnore rigorously often introduces a maintainability constraint, requiring teams to balance safer defaults against the risk of hiding data that legitimate system components still need.

  • A session token property is excluded from API responses so client applications never receive a secret that could be replayed.
  • An internal hash or checksum is marked with JsonIgnore so diagnostic objects can be serialized without exposing implementation details to downstream services.
  • A password-related field is omitted from outbound JSON while a separate validation path still processes the value before storage or verification.
  • A service model used for public responses carries both business data and operational metadata, but JsonIgnore keeps the internal metadata out of the response contract.
  • A developer pairs JsonIgnore with secure logging practices so NIST SP 800-53 style data handling expectations are preserved across APIs, logs, and message queues.

Why It Matters for Security Teams

JsonIgnore matters because many data exposures are not caused by advanced intrusion but by ordinary application behavior: object mapping, automatic serialization, and uncontrolled data propagation. When sensitive properties are not explicitly excluded, they can leak into API payloads, audit streams, message brokers, test fixtures, and analytics platforms. That creates unnecessary exposure of secrets and increases the blast radius of a coding mistake.

For security governance, JsonIgnore supports the broader objective reflected in the NIST Cybersecurity Framework 2.0, especially around data protection and secure software practices. It also fits naturally with secure SDLC expectations in OWASP Top 10 thinking, where sensitive data exposure is treated as a recurring application risk. Teams should still verify that the value is not copied into DTOs, logs, caches, or exceptions, because the attribute only governs JSON serialization behavior.

JsonIgnore becomes operationally unavoidable after a data exposure review or production incident reveals that a property thought to be internal has been published, logged, or forwarded beyond the service boundary.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack surface, NIST CSF 2.0, NIST SP 800-53 Rev 5 and NIST SP 800-63 set the technical controls, and ISO/IEC 27001:2022 define the regulatory obligations.

Framework Control / Reference Relevance
NIST CSF 2.0 PR.DS-1 Data-at-rest and in-transit protection includes limiting sensitive field exposure through serialization.
NIST SP 800-53 Rev 5 SI-10 Input/output validation and controlled handling support safe exclusion of sensitive properties.
ISO/IEC 27001:2022 ISO 27001 expects secure information handling across application processing and disclosure paths.
OWASP Non-Human Identity Top 10 Sensitive non-human identity secrets must not be serialized into logs or API payloads.
NIST SP 800-63 AAL2 Credential handling guidance is relevant when JSON objects contain authentication material.

Use serialization rules to prevent sensitive data from flowing into unintended systems or outputs.