PINE LIBRARY
업데이트됨 TO_JSON

TO_JSON
A lightweight Pine Script v6 library for converting TradingView series data into JSON-formatted alert payloads.
`TO_JSON` is designed for users who want to export chart data to external systems through TradingView alerts.
It helps transform rolling series such as OHLCV, indicator values, or text states into JSON-compatible arrays and wraps them into a structured message for webhooks, bots, dashboards, or automated workflows.
What this library does
This library provides helper functions to:
- convert float series into JSON arrays
- convert integer series into JSON arrays using a sentinel value as `null`
- convert string series into JSON arrays with fallback filling and JSON-safe escaping
- wrap custom payloads into a top-level JSON alert message with symbol, timeframe, timestamp, and token
It is especially useful when you want to send the latest `N` bars of market data or indicator values to an external service.
Features
- Rolling array export for `float`, `int`, and `string` series
- Chronological output from oldest to newest
- `null` support for missing values
- JSON-safe string escaping
- Simple wrapper for alert message generation
- Works well for webhook-based automation and downstream parsing
Exported functions
### `series_to_array_float_null(series float src, int N)`
Converts the latest `N` values of a float series into a JSON array string.
Missing values are exported as `null`.
`series_to_array_int_sentinel(series int src, int N, int sentinel)`
Converts the latest `N` values of an integer series into a JSON array string.
The specified sentinel value is exported as `null`.
`series_to_array_str_fill(series string src, int N, string fill="")`
Converts the latest `N` values of a string series into a JSON array string.
Missing values are replaced with `fill`, and strings are escaped for JSON compatibility.
`json(simple string token="1234567890", string info="", simple string symbol="AUTO")`
Wraps a custom JSON payload into a top-level alert message including:
- symbol
- timeframe
- current timestamp
- human-readable time
- info payload
- token
Typical use case
A common use case is exporting the last bars of:
- time
- open
- high
- low
- close
- volume
- moving averages
- custom signals
into one flat JSON object, then embedding it into the alert message.
Example
```pine
//version=6
import veegee82/TO_JSON/1 as json
indicator("TO_JSON Example", overlay=false)
stO = open
stH = high
stL = low
stC = close
stV = volume
ema_50 = ta.ema(close, 50)
ema_100 = ta.ema(close, 100)
ema_200 = ta.ema(close, 200)
ema_500 = ta.ema(close, 500)
ema_1000 = ta.ema(close, 1000)
json_flat(int n=50) =>
s_name = '"name":"' + 'vision_' + timeframe.period + '"'
s_tf = ',"timeframe":"' + timeframe.period + '"'
s_ts = ',"ts":' + json.series_to_array_float_null(time, n)
s_o = ',"open":' + json.series_to_array_float_null(stO, n)
s_h = ',"high":' + json.series_to_array_float_null(stH, n)
s_l = ',"low":' + json.series_to_array_float_null(stL, n)
s_c = ',"close":' + json.series_to_array_float_null(stC, n)
s_v = ',"volume":' + json.series_to_array_float_null(stV, n)
s_ema_50 = ',"ema_50":' + json.series_to_array_float_null(ema_50, n)
s_ema_100 = ',"ema_100":' + json.series_to_array_float_null(ema_100, n)
s_ema_200 = ',"ema_200":' + json.series_to_array_float_null(ema_200, n)
s_ema_500 = ',"ema_500":' + json.series_to_array_float_null(ema_500, n)
s_ema_1000 = ',"ema_1000":' + json.series_to_array_float_null(ema_1000, n)
"{" + s_name + s_tf + s_ts + s_o + s_h + s_l + s_c + s_v + s_ema_50 + s_ema_100 + s_ema_200 + s_ema_500 + s_ema_1000 + "}"
info = json_flat(100)
alert(
message = json.json(token = "1234567890", info = info, symbol = "AUTO"),
freq = alert.freq_once_per_bar_close
)
A lightweight Pine Script v6 library for converting TradingView series data into JSON-formatted alert payloads.
`TO_JSON` is designed for users who want to export chart data to external systems through TradingView alerts.
It helps transform rolling series such as OHLCV, indicator values, or text states into JSON-compatible arrays and wraps them into a structured message for webhooks, bots, dashboards, or automated workflows.
What this library does
This library provides helper functions to:
- convert float series into JSON arrays
- convert integer series into JSON arrays using a sentinel value as `null`
- convert string series into JSON arrays with fallback filling and JSON-safe escaping
- wrap custom payloads into a top-level JSON alert message with symbol, timeframe, timestamp, and token
It is especially useful when you want to send the latest `N` bars of market data or indicator values to an external service.
Features
- Rolling array export for `float`, `int`, and `string` series
- Chronological output from oldest to newest
- `null` support for missing values
- JSON-safe string escaping
- Simple wrapper for alert message generation
- Works well for webhook-based automation and downstream parsing
Exported functions
### `series_to_array_float_null(series float src, int N)`
Converts the latest `N` values of a float series into a JSON array string.
Missing values are exported as `null`.
`series_to_array_int_sentinel(series int src, int N, int sentinel)`
Converts the latest `N` values of an integer series into a JSON array string.
The specified sentinel value is exported as `null`.
`series_to_array_str_fill(series string src, int N, string fill="")`
Converts the latest `N` values of a string series into a JSON array string.
Missing values are replaced with `fill`, and strings are escaped for JSON compatibility.
`json(simple string token="1234567890", string info="", simple string symbol="AUTO")`
Wraps a custom JSON payload into a top-level alert message including:
- symbol
- timeframe
- current timestamp
- human-readable time
- info payload
- token
Typical use case
A common use case is exporting the last bars of:
- time
- open
- high
- low
- close
- volume
- moving averages
- custom signals
into one flat JSON object, then embedding it into the alert message.
Example
```pine
//version=6
import veegee82/TO_JSON/1 as json
indicator("TO_JSON Example", overlay=false)
stO = open
stH = high
stL = low
stC = close
stV = volume
ema_50 = ta.ema(close, 50)
ema_100 = ta.ema(close, 100)
ema_200 = ta.ema(close, 200)
ema_500 = ta.ema(close, 500)
ema_1000 = ta.ema(close, 1000)
json_flat(int n=50) =>
s_name = '"name":"' + 'vision_' + timeframe.period + '"'
s_tf = ',"timeframe":"' + timeframe.period + '"'
s_ts = ',"ts":' + json.series_to_array_float_null(time, n)
s_o = ',"open":' + json.series_to_array_float_null(stO, n)
s_h = ',"high":' + json.series_to_array_float_null(stH, n)
s_l = ',"low":' + json.series_to_array_float_null(stL, n)
s_c = ',"close":' + json.series_to_array_float_null(stC, n)
s_v = ',"volume":' + json.series_to_array_float_null(stV, n)
s_ema_50 = ',"ema_50":' + json.series_to_array_float_null(ema_50, n)
s_ema_100 = ',"ema_100":' + json.series_to_array_float_null(ema_100, n)
s_ema_200 = ',"ema_200":' + json.series_to_array_float_null(ema_200, n)
s_ema_500 = ',"ema_500":' + json.series_to_array_float_null(ema_500, n)
s_ema_1000 = ',"ema_1000":' + json.series_to_array_float_null(ema_1000, n)
"{" + s_name + s_tf + s_ts + s_o + s_h + s_l + s_c + s_v + s_ema_50 + s_ema_100 + s_ema_200 + s_ema_500 + s_ema_1000 + "}"
info = json_flat(100)
alert(
message = json.json(token = "1234567890", info = info, symbol = "AUTO"),
freq = alert.freq_once_per_bar_close
)
릴리즈 노트
v2fix token
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.