TradingView
MA_PT
6 de Feb. de 2022 18:11

json 

Starbucks CorporationNASDAQ

Descripción

Library "json"
Convert JSON strings to tradingview       
▦ FEATURES ▦                        
█ Json to array  █ Get json key names  █ Get json key values █ Size of json
                 

get_json_keys_names(raw_json) Returns string array with all key names
  Parameters:
    raw_json: (string) Raw JSON string
  Returns: (string array) Array with all key names

get_values_by_id_name(raw_json, key_name) Returns string array with values of the input key name
  Parameters:
    raw_json: (string) Raw JSON string
    key_name: (string) Name of the key to be fetched
  Returns: (string array) Array with values of the input key name

size_of_json_string(raw_json) Returns size of raw JSON string [n_of_values, n_of_keys_names]
  Parameters:
    raw_json: (string) Raw JSON string
  Returns: [int, int] Size of n_of_values, size of n_of_keys_names
Comentarios
moeinmoein2022
hi, thanks for you Library, that's Perfect
I'm new and try to learning Pine Script and i have a question about JSON.

i write this message and i want to send via Webhock to Python Server als JSON but it doesn't work

ticker = syminfo.ticker
position = array.from(message)
T1 = str.tostring(startPrice)
E1 = startPrice + diff * -0.27
E2 = startPrice + diff * -0.414
E3 = startPrice + diff * -0.618
SL = startPrice + diff * -0.786
if Short or Long
//values = array.from(str.tostring(ticker), str.tostring(message), str.tostring(E1), str.tostring(T1), str.tostring(E2), str.tostring(E1), str.tostring(E3), str.tostring(E2), str.tostring(SL))
//alertMessage = ra.updateAlertTemplate(template, keys, values)
Tmessage = '{"Ticker":"'+str.tostring(syminfo.ticker)+'",'+
//'"Position":'+str.tostring(message)+','+
'"Position":"'+str.tostring(message)+'",'+
'"Entry 1":"'+str.tostring(E1)+'",'+
'"Target 1":'+str.tostring(T1)+','+
'"Entry 2":'+str.tostring(E2)+','+
'"Target 2":'+str.tostring(E1)+','+
'"Entry 3":'+str.tostring(E3)+','+
'"Target 3":'+str.tostring(E2)+','+
'"Stop Lost":'+str.tostring(SL)+
'}'
alert(Tmessage, alert.freq_once_per_bar_close)
and it is my Error: "argument of type 'NoneType' is not iterable"

Could you held me?
BeeInvested
mJson = ticker.heikinashi(syminfo.ticker)
tickerText1 = json.get_json_keys_names(mJson)

I got empty string when using this, can I have an example of putting the inputs ?
MA_PT
@BeeInvested, Hi
ticker.heikinashi(symbol) → simple string
The function you used returns a simple, the json library is targeted to read JSON structure.
In your example, there's no JSON structure therefore returns "null"

Here's an example:
Where it returns the names of the available JSON from input and displays them in a table. Note: You can play around with the input

import MA_PT/json/1 as json import MA_PT/easytable/1 example_input = input.string('[{"Close":"10","Open":"9","PreMarket":"8"},{"Close":"12","Open":"10","PreMarket":"9"}]','INPUT') array_of_strings = json.get_json_keys_names(example_input) tbl = easytable.create_table_clean(5,array.size(array_of_strings)) easytable.array_to_table_row(tbl,0,array_of_strings)


Más