Err just a dumb question, sorry for that. But why don’t you just add that by yourself when recieving it?
Example in PHP
<?php
$j='{"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]}';
$d=json_decode($j,true);
$d['timestamp']=time();
echo json_encode($d);
Example in Python
import json, time
j = '{"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]}'
d = json.loads(j)
d["timestamp"] = int(time.time())
print(json.dumps(d))
Example in JavaScript
let j = '{"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]}';
let d = JSON.parse(j);
d.timestamp = Math.floor(Date.now() / 1000);
console.log(JSON.stringify(d));
Example in Ruby
require 'json'
j = '{"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]}'
d = JSON.parse(j)
d["timestamp"] = Time.now.to_i
puts d.to_json
Example in Go
package main
import (
"encoding/json"
"fmt"
"time"
)
func main() {
j := `{"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]}`
var d map[string]interface{}
json.Unmarshal([]byte(j), &d)
d["timestamp"] = time.Now().Unix()
b, _ := json.Marshal(d)
fmt.Println(string(b))
}
Example in Rust
use serde_json::Value;
use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
let j = r#"{"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]}"#;
let mut d: Value = serde_json::from_str(j).unwrap();
d["timestamp"] = serde_json::json!(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs());
println!("{}", d.to_string());
}
Example in Swift
import Foundation
let j = """
{"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]}
"""
var d = try! JSONSerialization.jsonObject(with: j.data(using: .utf8)!) as! [String: Any]
d["timestamp"] = Int(Date().timeIntervalSince1970)
let jsonData = try! JSONSerialization.data(withJSONObject: d)
print(String(data: jsonData, encoding: .utf8)!)
Example in Kotlin
import org.json.JSONObject
fun main() {
val j = """{"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]}"""
val d = JSONObject(j)
d.put("timestamp", System.currentTimeMillis() / 1000)
println(d.toString())
}
Example in Elixir
j = ~s({"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]})
d = Jason.decode!(j)
d = Map.put(d, "timestamp", :os.system_time(:second))
IO.puts Jason.encode!(d)
Example in F#
open System
open System.Text.Json
let j = """{"messages":[{"role":"user","content":"Hello!"},{"role":"assistant","content":"Hi! How can I help?"}]}"""
let mutable d = JsonSerializer.Deserialize<Map<string, obj>>(j)
d <- d.Add("timestamp", DateTimeOffset.UtcNow.ToUnixTimeSeconds())
printfn "%s" (JsonSerializer.Serialize(d))