Skip to main content

escape_json_string

Function escape_json_string 

Source
pub fn escape_json_string(s: &str, _context: EscapeContext) -> String
Expand description

Escape a string for embedding in JSON strings.

JSON has strict escaping rules for special characters including quotes, backslashes, newlines, tabs, and control characters.

§Arguments

  • s - The string to escape
  • context - The target language context

§Returns

A string with JSON-safe escape sequences

§Examples

use spikard_cli::codegen::common::escaping::{EscapeContext, escape_json_string};

let result = escape_json_string("line1\nline2\t\"quoted\"", EscapeContext::Rust);
assert!(result.contains("\\n"));
assert!(result.contains("\\t"));
assert!(result.contains("\\\""));