PINE LIBRARY
Updated

jsonBuilder

175
Library "jsonBuilder"

jsonBuilder is a lightweight Pine Script utility library for building JSON strings manually. It includes functions to convert key-value pairs into JSON format and to combine multiple pairs into a complete JSON object.

jsonString(key, value) – Converts a string key and string value into a valid JSON key-value pair.

jsonObject(pair1, ..., pair20) – Merges up to 20 key-value pairs into a complete JSON object string. Empty arguments are skipped automatically.

This is useful when sending structured JSON data via webhooks or external integrations from Pine Script.
Release Notes
v2

Pine Script®
// Create JSON key-value pairs
symbolKV = jsonBuilder.jsonString("symbol", syminfo.ticker)
priceKV  = jsonBuilder.jsonString("price", str.tostring(close, "#.##"))
timeKV   = jsonBuilder.jsonString("time", str.tostring(time))

// Combine pairs into a complete JSON object
json = jsonBuilder.jsonObject(symbolKV, priceKV, timeKV)

Pine Script®
{
  "symbol": "BTCUSD",
  "price": "70823.45",
  "time": "1713108494000"
}

Pine Script®
json = jsonBuilder.jsonObject(
    jsonBuilder.jsonString("symbol", syminfo.ticker),
    jsonBuilder.jsonString("price", str.tostring(close, "#.##")),
    jsonBuilder.jsonString("time", str.tostring(time))
)

Pine Script®
{"symbol": "ETHUSD", "price": "3582.10", "time": "1713111120000"}

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.