cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-208546%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EC%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-208546%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ETodo%2C%3CBR%20%2F%3E%20Me%20pregunto%20c%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%20en%20JSL.%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Erequest%20%3D%20New%20HTTP%20Request(%0A%20url(%20%22http%3A%2F%2Fhttpbin.org%2Fpost%22%20)%2C%0A%20Method(%20%22POST%22%20)%2C%0A%20JSON(%20%22%5C%5B%7B%22username%22%3A%22bob%22%2C%22address%22%3A%2212345%22%7D%5D%5C%22%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EUsando%20el%20ejemplo%20del%20%C3%ADndice%20de%20secuencias%20de%20comandos%2C%20si%20quisiera%20cambiar%20el%20nombre%20de%20usuario%20de%20bob%20para%20decir%20marca%20y%20direcci%C3%B3n%20de%2012345%20a%2012346%20y%20tengo%2010%20de%20esas%20llamadas%2C%20preferir%C3%ADa%20construir%20eso%20como%20un%20objeto%20din%C3%A1mico%20afuera.%20Inicialmente%20me%20aventur%C3%A9%20por%20el%20camino%20de%20construirlo%20como%20una%20matriz%20asociativa%20y%20luego%20usar%20As%20JSON%20Expr()%20%2C%20sin%20embargo%2C%20eso%20est%C3%A1%20dando%20como%20resultado%20un%20error.%20Mi%20enfoque%20en%20ese%20caso%20fue%3A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EMyAA%20%3D%20Associative%20Array()%3B%20%0AMyAA%5B%22username%22%5D%20%3D%20%22bob%22%20%3B%20%0AMyAA%5B%22address%22%5D%20%3D%20%2212345%22%20%3B%3CBR%20%2F%3E%3CBR%20%2F%3Erequest%20%3D%20New%20HTTP%20Request(%0A%20url(%20%22http%3A%2F%2Fhttpbin.org%2Fpost%22%20)%2C%0A%20Method(%20%22POST%22%20)%2C%0A%20JSON(%20As%20Json%20Expr(MyAA))%20%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EPor%20supuesto%2C%20esto%20no%20sucede%20en%20este%20ejemplo%2C%20sino%20en%20la%20API%20a%20la%20que%20intento%20llamar.%20Sin%20embargo%2C%20cuando%20paso%20JSON%20codificado%20como%20entrada%2C%20la%20llamada%20API%20funciona%20como%20se%20esperaba.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20896px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20896px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20896px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F17242iCD8011C9634ED134%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3ECualquier%20ayuda%20es%20apreciada.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210170%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210170%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EEso%20fue%20para%20construirlo%20paso%20a%20paso%2C%20la%20versi%C3%B3n%20completa%20%22codificada%22%20ser%C3%ADa%20solo%3CBR%20%2F%3E%20factores%20mensuales%20%3D%20%7B%20%7B%3CBR%20%2F%3E%20%5B%20%22month%22%20%3D%26gt%3B%201%2C%20%22month_name%22%20%3D%26gt%3B%20%22Jan%22%2C%20%22albedo%22%20%3D%26gt%3B%200.2%2C%20%22soiling_loss%22%20%3D%26gt%3B%202.0%5D%2C%3CBR%20%2F%3E%20%5B%20%22mes%22%20%3D%26gt%3B%202%2C%20%22mes_nombre%22%20%3D%26gt%3B%20%22febrero%22%2C%20%22albedo%22%20%3D%26gt%3B%200%2C2%2C%20%22p%C3%A9rdida_de_suciedad%22%20%3D%26gt%3B%202%2C0%5D%2C%3CBR%20%2F%3E%20%5B%20%22month%22%20%3D%26gt%3B%203%2C%20%22month_name%22%20%3D%26gt%3B%20%22Mar%22%2C%20%22albedo%22%20%3D%26gt%3B%200.2%2C%20%22soiling_loss%22%20%3D%26gt%3B%202.0%5D%3CBR%20%2F%3E%20%7D%7D%3B%3CBR%20%2F%3E%20je%20%3D%20As%20Expr%20JSON%20(factores%20mensuales)%3B%3CBR%20%2F%3E%20Mostrar(je)%3B%3CBR%20%2F%3E%20Como%20una%20regla%20de%20oro%3A%3CBR%20%2F%3E%20*%20Las%20matrices%20JSON%20se%20asignan%20a%20listas%20JSL%20(no%20matrices%20ni%20vectores%2C%20tenga%20cuidado%20con%20la%20similitud%20'%5B%5D')%3B%3CBR%20%2F%3E%20*%20Los%20diccionarios%20JSON%20se%20asignan%20a%20matrices%20asociativas%20JSL%3B%3CBR%20%2F%3E%20*%20Verificaci%C3%B3n%20de%20referencias%20de%20variables%20no%20evaluadas%3B%3CBR%20%2F%3E%20*%20Compruebe%20si%20las%20llamadas%20de%20modificaci%C3%B3n%20de%20la%20estructura%20de%20datos%20realmente%20cambian%20el%20objeto%20de%20destino%20(en%20lugar%20de%20devolver%20una%20copia%20modificada).%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210169%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210169%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EY%20no%20olvide%20que%20puede%20crear%20JSON%20simplemente%20concatenando%20cadenas%20en%20el%20formato%20JSON.%3C%2FP%3E%0A%3CP%3ENo%20se%20necesitan%20listas%20ni%20matrices%20asociativas.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210168%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210168%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESi%20lo%20reescribo%20as%C3%AD%20usando%20Chrome%20Add%20en%20JSON%20Editor%2C%20veo%20una%20lista%20de%20matrices%20asociativas%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%5B%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%201%2C%0A%20%20%20%20%22month_name%22%3A%20%22Jan%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%202%2C%0A%20%20%20%20%22month_name%22%3A%20%22Feb%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%203%2C%0A%20%20%20%20%22month_name%22%3A%20%22Mar%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%204%2C%0A%20%20%20%20%22month_name%22%3A%20%22Apr%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%205%2C%0A%20%20%20%20%22month_name%22%3A%20%22May%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%206%2C%0A%20%20%20%20%22month_name%22%3A%20%22Jun%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%207%2C%0A%20%20%20%20%22month_name%22%3A%20%22Jul%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%208%2C%0A%20%20%20%20%22month_name%22%3A%20%22Aug%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%209%2C%0A%20%20%20%20%22month_name%22%3A%20%22Sep%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%2010%2C%0A%20%20%20%20%22month_name%22%3A%20%22Oct%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%2011%2C%0A%20%20%20%20%22month_name%22%3A%20%22Nov%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20%22month%22%3A%2012%2C%0A%20%20%20%20%22month_name%22%3A%20%22Dec%22%2C%0A%20%20%20%20%22albedo%22%3A%200.2%2C%0A%20%20%20%20%22soiling_loss%22%3A%202%0A%20%20%7D%0A%5D%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screen%20Shot%202019-05-22%20at%202.00.57%20PM.png%22%20style%3D%22width%3A%20304px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Screen%20Shot%202019-05-22%20at%202.00.57%20PM.png%22%20style%3D%22width%3A%20304px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Screen%20Shot%202019-05-22%20at%202.00.57%20PM.png%22%20style%3D%22width%3A%20304px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F17367iEE642D23752E3BCF%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screen%20Shot%202019-05-22%20at%202.00.57%20PM.png%22%20alt%3D%22Screen%20Shot%202019-05-22%20at%202.00.57%20PM.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210167%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210167%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EEsto%20parece%20funcionar.%3CBR%20%2F%3E%20ListaInterior%20%3D%20%7B%7D%3B%3CBR%20%2F%3E%20InsertInto(innerList%2C%20%5B%20%22month%22%20%3D%26gt%3B%201%2C%20%22month_name%22%20%3D%26gt%3B%20%22Jan%22%2C%20%22albedo%22%20%3D%26gt%3B%200.2%2C%20%22soiling_loss%22%20%3D%26gt%3B%202.0%5D)%3B%3CBR%20%2F%3E%20InsertInto(innerList%2C%20%5B%20%22month%22%20%3D%26gt%3B%202%2C%20%22month_name%22%20%3D%26gt%3B%20%22Feb%22%2C%20%22albedo%22%20%3D%26gt%3B%200.2%2C%20%22soiling_loss%22%20%3D%26gt%3B%202.0%5D)%3B%3CBR%20%2F%3E%20InsertInto(innerList%2C%20%5B%20%22month%22%20%3D%26gt%3B%203%2C%20%22month_name%22%20%3D%26gt%3B%20%22Mar%22%2C%20%22albedo%22%20%3D%26gt%3B%200.2%2C%20%22soiling_loss%22%20%3D%26gt%3B%202.0%5D)%3B%3CBR%20%2F%3E%20factoresmensuales%20%3D%20%7BlistaInterior%7D%3B%3CBR%20%2F%3E%20je%20%3D%20As%20JSON%20Expr(EvalList(mensualFactors))%3B%3CBR%20%2F%3E%20Mostrar(je)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%20Creo%20que%20el%20verdadero%20problema%20es%20conocer%20las%20llamadas%20API%20correctas%20a%20la%20lista%20JSL%20y%20las%20estructuras%20de%20datos%20de%20matrices%20asociativas%2C%20y%20su%20comportamiento%20en%20cuanto%20a%20la%20evaluaci%C3%B3n%20de%20variables%2C%20la%20devoluci%C3%B3n%20de%20una%20copia%20frente%20a%20una%20referencia%20en%20vivo%2C%20etc.%20El%20hecho%20de%20que%20se%20utilicen%20para%20construir%20un%20objeto%20JSON%20es%20incidental.%3CBR%20%2F%3E%3CBR%20%2F%3E%20Habiendo%20dicho%20eso%2C%20con%20el%20nuevo%20soporte%20para%20REST%20API%20de%20JMP%2C%20estoy%20de%20acuerdo%20en%20que%20ser%C3%ADa%20%C3%BAtil%20tener%20una%20sesi%C3%B3n%20con%20un%20ejemplo%20m%C3%A1s%20detallado%20y%20completo.%20Pasar%C3%A9%20esta%20sugerencia%20solo%20a%20nuestro%20equipo%20de%20doc.%20%C2%A1Gracias%20por%20la%20sugerencia!%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210165%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210165%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3Eah%3C%2FP%3E%0A%3CP%3ETuve%20un%20error%20de%20transcripci%C3%B3n%20al%20pasar%20de%20la%20imagen%20al%20texto.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210163%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210163%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%C2%BFTienes%20el%20enlace%20a%20la%20API.%20No%20creo%20que%20hayas%20enumerado%20JSON%20v%C3%A1lido.%3CBR%20%2F%3E%20Al%20menos%20el%20Editor%20JSON%20en%20Chrome%20no%20lo%20cree%20as%C3%AD.%3CBR%20%2F%3E%20Gracias%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210149%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210149%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3734%22%20target%3D%22_blank%22%3E%40nascif_jmp%3C%2FA%3E%20y%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5036%22%20target%3D%22_blank%22%3E%20%40bryan_boone%3C%2FA%3E%20%2C%3C%2FP%3E%3CP%3EGracias%20por%20sus%20respuestas.%20Sus%20respuestas%20me%20ayudaron%20a%20llegar%20a%20alguna%20parte%2C%20sin%20embargo%2C%20tengo%20un%20par%20de%20preguntas%3A%3C%2FP%3E%3CP%3E1.%20%C2%BFPuede%20proporcionarnos%20un%20ejemplo%20de%20formato%20de%20matriz%20JSON%20aceptado%20en%20JSL%3F%20%C2%BFEs%20esto%20aceptado%3F%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20706px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20706px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20706px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F17365i94623AB9312F39C4%2Fimage-dimensions%2F706x263%3Fv%3Dv2%22%20width%3D%22706%22%20height%3D%22263%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E2.%20%C2%BFEl%20%C3%ADndice%20de%20secuencias%20de%20comandos%20o%20la%20gu%C3%ADa%20de%20secuencias%20de%20comandos%20cubren%20las%20partes%20en%20la%20matriz%20JSON%20o%20c%C3%B3mo%20definir%20un%20objeto%20JSON%20vac%C3%ADo%20como%20nasicf%20ha%20mostrado%20amablemente%3F%3CBR%20%2F%3E%20a.%20Si%20es%20as%C3%AD%2C%20me%20gustar%C3%ADa%20leer%20eso.%3CBR%20%2F%3E%20b.%20Si%20no%2C%20solicitar%C3%ADa%20que%20esto%20se%20agregue%20a%20la%20documentaci%C3%B3n%2C%20porque%20no%20pude%20encontrarlo%20en%20ning%C3%BAn%20lado%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-209539%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-209539%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELa%20sintaxis%20de%20JavaScript%2FPython%20para%20las%20listas%20(%22%5B%5D%22)%20no%20significa%20lo%20mismo%20en%20JSL.%20En%20JSL%20'%5B%5D'%20denota%20un%20vac%C3%ADo%3CEM%3E%20matriz%2C%3C%2FEM%3E%20que%20no%20tiene%20una%20representaci%C3%B3n%20JSON%20v%C3%A1lida%2C%20por%20lo%20que%20est%C3%A1%20obteniendo%20el%20'%3F'%20operador%20en%20el%20resultado.%20Eso%20'%3F'%20el%20operador%2C%20a%20su%20vez%2C%20debe%20ser%20lo%20que%20est%C3%A1%20causando%20el%20mensaje%20de%20error%20remoto%20que%20est%C3%A1%20recibiendo%20como%20respuesta%20de%20su%20servicio.%3C%2FP%3E%0A%3CP%3EDeber%C3%ADa%20usar%20en%20su%20lugar%20'%7B%7D'%20para%20indicar%20una%20lista%20vac%C3%ADa%2C%20o%20'%5B%3D%26gt%3B%5D'%20para%20indicar%20una%20matriz%2Fdiccionario%20asociativo%20vac%C3%ADo.%3C%2FP%3E%0A%3CP%3ESiempre%20es%20una%20buena%20pr%C3%A1ctica%20capturar%20resultados%20intermedios%20y%20examinarlos%20usando%20show()%20para%20probar%20sus%20suposiciones.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwiki.c2.com%2F%3FMakeItWorkMakeItRightMakeItFast%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwiki.c2.com%2F%3FMakeItWorkMakeItRightMakeItFast%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-209528%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-209528%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPuede%20crear%20JSON%20%22din%C3%A1mico%22%2C%20pero%20tendr%C3%ADa%20que%20agregar%20sus%20subelementos%20a%20la%20matriz%20asociativa%20despu%C3%A9s%20de%20que%20se%20hayan%20creado.%3C%2FP%3E%0A%3CP%3EAs%C3%AD%20es%20como%20funciona%20JSL.%3C%2FP%3E%0A%3CP%3EEsto%20muestra%20lo%20que%20quiero%20decir%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eaa%20%3D%20%5B%3D%26gt%3B%5D%3B%0Alist%20%3D%20%7B%7D%3B%0Aaa%5B%22a%20jsl%20list%22%5D%20%3D%20list%3B%0A%0AInsert%20Into(list%2C%20%22Hello%20World%22)%3B%0AInsert%20Into(list%2C%202019)%3B%0A%0Ashow(list)%3B%0Ashow(aa)%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Esalidas%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Elist%20%3D%20%7B%22Hello%20World%22%2C%202019%7D%3B%0Aaa%20%3D%20%5B%22a%20jsl%20list%22%20%3D%26gt%3B%20%7B%7D%5D%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EMientras%20esto%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eaa%20%3D%20%5B%3D%26gt%3B%5D%3B%0Alist%20%3D%20%7B%7D%3B%0A%0AInsert%20Into(list%2C%20%22Hello%20World%22)%3B%0AInsert%20Into(list%2C%202019)%3B%0A%0Aaa%5B%22a%20jsl%20list%22%5D%20%3D%20list%3B%0A%0Ashow(list)%3B%0Ashow(aa)%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESalidas%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Elist%20%3D%20%7B%22Hello%20World%22%2C%202019%7D%3B%0Aaa%20%3D%20%5B%22a%20jsl%20list%22%20%3D%26gt%3B%20%7B%22Hello%20World%22%2C%202019%7D%5D%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-208878%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-208878%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ENo%20he%20seguido%20este%20hilo%20en%20absoluto%2C%20pero%20vi%20una%20menci%C3%B3n%20del%20uso%20de%20matrices%20asociativas%20y%20lo%20que%20parec%C3%ADa%20una%20confusi%C3%B3n%20sobre%20el%20resultado%20predeterminado.%20Ese%20es%20el%20%C3%BAnico%20aspecto%20al%20que%20estoy%20respondiendo.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EVer%3CSTRONG%3E%20Ayuda%3C%2FSTRONG%3E%20%26gt%3B%3CSTRONG%3E%20Libros%3C%2FSTRONG%3E%20%26gt%3B%3CSTRONG%3E%20Gu%C3%ADa%20de%20secuencias%20de%20comandos%3C%2FSTRONG%3E%20y%20busque%20matrices%20asociativas%20en%20la%20Tabla%20de%20contenido%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EValores%20predeterminados%3C%2FSTRONG%3E%3CBR%20%2F%3E%20Un%20valor%20predeterminado%20determina%20el%20valor%20de%20una%20clave%20que%20no%20existe%20en%20una%20matriz%20asociativa.%20Si%20usted%3CBR%20%2F%3E%20intente%20acceder%20a%20una%20clave%20que%20no%20existe%20en%20una%20matriz%20asociativa%2C%20se%20produce%20un%20error.%20Si%20defines%20un%3CBR%20%2F%3E%20valor%20predeterminado%20para%20su%20matriz%20asociativa%2C%20acceder%20a%20una%20clave%20que%20no%20existe%20da%20como%20resultado%20el%3CBR%20%2F%3E%20siguiente%3A%3CBR%20%2F%3E%20%E2%80%A2%20agrega%20la%20clave%20a%20la%20matriz%20asociativa%3CBR%20%2F%3E%20%E2%80%A2%20asigna%20el%20valor%20predeterminado%20a%20la%20nueva%20clave%3CBR%20%2F%3E%20%E2%80%A2%20devuelve%20el%20valor%20(predeterminado)%20de%20la%20nueva%20clave%20en%20lugar%20de%20un%20error%3CBR%20%2F%3E%20Si%20construye%20una%20matriz%20asociativa%20a%20partir%20de%20una%20lista%20de%20cadenas%20sin%20asignar%20valores%20a%20las%20claves%2C%3CBR%20%2F%3E%20entonces%20a%20las%20claves%20se%20les%20asignan%20valores%20de%201.%20El%20valor%20predeterminado%20para%20la%20matriz%20asociativa%20se%20establece%20en%200.%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3EPara%20establecer%20el%20valor%20predeterminado%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ecary%20%3D%20Associative%20Array()%3B%0Acary%20%26lt%3B%26lt%3B%20Set%20Default%20Value(%20%22Cary%2C%20NC%22%20)%3B%3CBR%20%2F%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPara%20determinar%20si%20hay%20un%20valor%20predeterminado%20establecido%20para%20una%20matriz%20asociativa%2C%20use%20el%20comando%20%26lt%3B%3CGET%3E%3CBR%20%2F%3E%20Mensaje%20de%20valor%20predeterminado.%3C%2FGET%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ecary%20%26lt%3B%26lt%3B%20Get%20Default%20Value%3B%0A%22Cary%2C%20NC%22%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3ESi%20no%20hay%20un%20valor%20predeterminado%2C%20se%20devuelve%20Empty().%3CBR%20%2F%3E%20Adem%C3%A1s%20del%20mensaje%20Establecer%20valor%20predeterminado%2C%20se%20puede%20establecer%20un%20valor%20predeterminado%20en%20el%20constructor%20literal%3CBR%20%2F%3E%20usando%20%3D%26gt%3B%20valor%20sin%20una%20clave.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ecounts%20%3D%20%5B%22a%22%20%3D%26gt%3B%2010%2C%0A%22b%22%20%3D%26gt%3B%203%2C%0A%3D%26gt%3B%200%5D%3B%20%2F%2F%20default%20value%20of%200%0Acounts%5B%22c%22%5D%20%2B%3D%201%3B%0AShow(%20counts%20)%3B%0Acounts%20%3D%20%5B%22a%22%20%3D%26gt%3B%2010%2C%20%22b%22%20%3D%26gt%3B%203%2C%20%22c%22%20%3D%26gt%3B%201%2C%20%3D%26gt%3B%200%5D%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3EEn%20la%20primera%20l%C3%ADnea%2C%20el%20valor%20predeterminado%20se%20establece%20en%200.%20En%20la%20segunda%20l%C3%ADnea%2C%20la%20clave%20%22c%22%20no%20existe%20en%3CBR%20%2F%3E%20cuenta%20En%20la%20salida%2C%20la%20clave%20%22c%22%20se%20crea%20con%20el%20valor%20predeterminado%20de%200%20y%20luego%20se%20incrementa%3CBR%20%2F%3E%20por%201.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3ENota%3A%20si%20el%20valor%20de%20una%20clave%20es%20el%20valor%20predeterminado%2C%20la%20clave%20se%20descarta%20porque%20cualquier%20clave%20devolver%C3%A1%3CBR%20%2F%3E%20el%20valor%20predeterminado.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-208852%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-208852%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5358%22%20target%3D%22_blank%22%3E%40Mark_Bailey%3C%2FA%3E%20%2C%3C%2FP%3E%3CP%3ECuando%20uso%20%22%5B%20%5D%22%20%2C%20eso%20da%20como%20resultado%20un%20error.%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20896px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20896px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20896px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F17271iB2DB3CB89A2649BF%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-208851%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-208851%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPuede%20definir%20cualquier%20resultado%20que%20desee%20que%20se%20devuelva%20al%20hacer%20referencia%20a%20una%20clave%20que%20no%20tiene%20un%20valor%20en%20un%20par%20en%20una%20matriz%20asociativa.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-208850%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-208850%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%C2%BFPuedo%20recomendar%20en%20primer%20lugar%20que%20no%20solo%20copie%20una%20imagen%2C%20sino%20que%20use%20la%20funcionalidad%20del%20c%C3%B3digo%20JSL%20para%20que%20las%20personas%20puedan%20copiar%20y%20pegar%20su%20c%C3%B3digo%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESupongo%20que%20est%C3%A1s%20tratando%20de%20dar%20un%20vector%20al%20nombre%20de%20usuario.%3CBR%20%2F%3ETodav%C3%ADa%20no%20tengo%20que%20fallar%20con%20httpbin%2C%20aunque%20todav%C3%ADa%20est%C3%A1%20haciendo%20lo%20extra%C3%B1o%20del%20operador.Si%20us%C3%A9%20una%20lista%20en%20lugar%20de%20una%20matriz%2C%20parece%20hacer%20lo%20que%20creo%20que%20quieres.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20default%20to%20here(1)%3B%0AMyAA%20%3D%20Associative%20Array()%3B%0AMyAA%5B%22username%22%5D%20%3D%20%7B1%2C%202%2C%203%7D%3B%0AMyAA%5B%22address%22%5D%20%3D%20%2212345%22%3B%0Arequest%20%3D%20New%20HTTP%20Request(%0A%20url(%20%22http%3A%2F%2Fhttpbin.org%2Fpost%22%20)%2C%0A%20Method(%20%22POST%22%20)%2C%0A%20JSON(%20AsJSONExpr(myAA)%20)%0A)%3B%0Adata%20%3D%20request%20%26lt%3B%26lt%3B%20Send%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%C2%BFEso%20ayuda%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-208830%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-208830%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2610%22%20target%3D%22_blank%22%3E%40vince_faller%3C%2FA%3E%20%2C%3C%2FP%3E%3CP%3EAs%C3%AD%20que%20el%20problema%20se%20deriva%20de%20esto%3A%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20609px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20609px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20609px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F17270i258D690AB512EDEE%2Fimage-dimensions%2F609x248%3Fv%3Dv2%22%20width%3D%22609%22%20height%3D%22248%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESi%20la%20matriz%20asociativa%20tiene%20una%20clave%20sin%20valor%2C%20luego%20de%20usar%20As%20JSON%20Expr()%2C%20se%20traduce%20a%20este%20operador%20extra%C3%B1o%20(%3F)%20Que%20no%20es%20algo%20que%20pueda%20analizarse%20correctamente%2C%20lo%20que%20a%20su%20vez%20genera%20un%20error.%20En%20mi%20caso%2C%20acabo%20de%20soltar%20la%20clave%20de%20mi%20matriz%20asociativa%20y%20funcion%C3%B3%2C%20sin%20embargo%2C%20tengo%20curiosidad%20por%20saber%20cu%C3%A1l%20es%20la%20forma%20correcta%20de%20pasar%20dicho%20par%C3%A1metro.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-208674%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-208674%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2610%22%20target%3D%22_blank%22%3E%40vince_faller%3C%2FA%3E%20%2C%3CBR%20%2F%3E%20Como%20algunos%20de%20los%20par%C3%A1metros%20no%20son%20algo%20que%20pueda%20compartir%20aqu%C3%AD%2C%20te%20lo%20envi%C3%A9%20como%20un%20mensaje%20privado.%20Ver%C3%A1%20en%20el%20mensaje%20que%20el%20ejemplo%20codificado%20y%20As%20JSON%20Expr()%20tienen%20los%20mismos%20par%C3%A1metros%2C%20los%20valores%20son%20din%C3%A1micos%2C%20pero%20da%20como%20resultado%20un%20error%20como%20lo%20mostr%C3%A9%20anteriormente.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-208666%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20C%C3%B3mo%20construir%20un%20objeto%20JSON%20din%C3%A1mico%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-208666%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%C2%BFHa%20confirmado%20que%20su%20AS%20JSON%20Expr%20()%20es%20el%20mismo%20que%20su%20codificado%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELa%20construcci%C3%B3n%20del%20objeto%20JSON%20parece%20estar%20funcionando.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20default%20to%20here(1)%3B%0AMyAA%20%3D%20Associative%20Array()%3B%20%0AMyAA%5B%22username%22%5D%20%3D%20%22bob%22%20%3B%20%0AMyAA%5B%22address%22%5D%20%3D%20%2212345%22%20%3B%0AmyAA%5B%22aa%22%5D%20%3D%20associative%20array()%3B%0AmyAA%5B%22aa%22%5D%5B%22thing1%22%5D%20%3D%2014%3B%0AmyAA%5B%22aa%22%5D%5B%22thing2%22%5D%20%3D%2028%3B%0A%0Ashow(%20As%20JSON%20Expr(myAA))%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
uday_guntupalli
Level VIII

How to build a dynamic JSON object

All, 
    I am wondering how to build a dynamic JSON object in JSL ? 

request = New HTTP Request(
	url( "http://httpbin.org/post" ),
	Method( "POST" ),
	JSON( "\[{"username":"bob","address":"12345"}]\" )
);

   Using the example from the scripting index, if I wantedt to vary the username from bob to say mark and address from 12345 to 12346 and I have 10 such calls, I would prefer building that as a dynamic object outside. I initially ventured down the path of building it as an Associative Array and then using the As JSON Expr() , however, that is resulting in an error. My approach in that case was: 

MyAA = Associative Array(); 
MyAA["username"] = "bob" ; 
MyAA["address"] = "12345" ;

request = New HTTP Request( url( "http://httpbin.org/post" ), Method( "POST" ), JSON( As Json Expr(MyAA)) );

Of course, this is not happening for this example, but the api I am trying to call on. However, when I pass hardcoded JSON as an input, the api call works as expected. 

 

image.png

Any help is appreciated. 

Best
Uday
16 REPLIES 16
uday_guntupalli
Level VIII

Re: How to build a dynamic JSON object

@nascif_jmp  and @bryan_boone ,

        Thank you for your responses. Your responses helped me get somewhere, however I have a couple of questions: 

1. Can you kindly provide an example of accepted JSON array format in JSL ? Is this accepted ?

image.png

2. Does the scripting index or scripting guide cover the portions on JSON array or how to define an empty JSON object as nasicf has kindly shown ? 
   a. If yes, I would like to read that 
   b. If no, I would request that this be added to the documentation, because I couldn't find it anywhere 

Best
Uday

Re: How to build a dynamic JSON object

Do you have the link to the API. I don't think you've listed valid JSON.
At least the JSON Editor in Chrome doesn't think so.
Thanks

Re: How to build a dynamic JSON object

Ah.

I had a transcribing error going from picture to text.

 

Re: How to build a dynamic JSON object

If I rewrite it like this using the chrome add in JSON Editor, I see a List of Associative Arrays

 

[
  {
    "month": 1,
    "month_name": "Jan",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 2,
    "month_name": "Feb",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 3,
    "month_name": "Mar",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 4,
    "month_name": "Apr",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 5,
    "month_name": "May",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 6,
    "month_name": "Jun",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 7,
    "month_name": "Jul",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 8,
    "month_name": "Aug",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 9,
    "month_name": "Sep",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 10,
    "month_name": "Oct",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 11,
    "month_name": "Nov",
    "albedo": 0.2,
    "soiling_loss": 2
  },
  {
    "month": 12,
    "month_name": "Dec",
    "albedo": 0.2,
    "soiling_loss": 2
  }
]

 Screen Shot 2019-05-22 at 2.00.57 PM.png

nascif_jmp
Level VI

Re: How to build a dynamic JSON object

This seems to work.
innerList = {};
InsertInto(innerList, [ "month" => 1, "month_name" => "Jan", "albedo" => 0.2, "soiling_loss" => 2.0]);
InsertInto(innerList, [ "month" => 2, "month_name" => "Feb", "albedo" => 0.2, "soiling_loss" => 2.0]);
InsertInto(innerList, [ "month" => 3, "month_name" => "Mar", "albedo" => 0.2, "soiling_loss" => 2.0]);
monthlyFactors = {innerList};
je = As JSON Expr(EvalList(monthlyFactors));
Show(je);

I think the real issue is knowing the right API calls to the JSL list and associative arrays data structures, and their behavior as far as evaluating variables, returning a copy vs a live reference, and so on. The fact that they are being used to build a JSON object is incidental.

Having said that, with the new support for REST APIs from JMP I agree that having a session with a more detailed, end-to-end example would be helpful. I will pass this sugestion alone to our doc team. Thanks for the suggestion!

Re: How to build a dynamic JSON object

And don't forget you can create JSON by just concatenating strings in the JSON format.

No Lists or Associative Arrays needed.

nascif_jmp
Level VI

Re: How to build a dynamic JSON object

That was for building it step by step, the complete "hardcoded" version would be just
monthlyFactors = { {
[ "month" => 1, "month_name" => "Jan", "albedo" => 0.2, "soiling_loss" => 2.0],
[ "month" => 2, "month_name" => "Feb", "albedo" => 0.2, "soiling_loss" => 2.0],
[ "month" => 3, "month_name" => "Mar", "albedo" => 0.2, "soiling_loss" => 2.0]
}};
je = As JSON Expr(monthlyFactors);
Show(je);
As a rule of thumb:
* JSON arrays map to JSL lists (not matrices or vectors, beware of the '[]' similarity);
* JSON dictionaries map to JSL associative arrays;
* Check for non-evaluated variable references;
* Check if data structure modifying calls actually change the target object (as opposed to returning a modified copy).

Recommended Articles