• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • CSPro Program Structure
      • Programming Standards
      • Change Code Properties
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
      • Procedural Sections
      • Logic
      • Language Elements
      • JavaScript Use in CSPro
        • Overview
        • JS Namespace
        • JS.eval Function
        • JS.invoke Function
        • JS.getValue Function
        • JS.getValueJson Function
        • JS.hasValue Function
        • JS.setValue Function
        • JS.setValueFromJson Function
        • JavaScript User-Defined Functions
        • CSPro ⇄ JavaScript Value Conversions
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

JS.getValueJson Function

Format
s = JS.getValueJson(name);
Description
The JS.getValueJson function returns the JSON representation of a JavaScript variable or property by calling the JSON.stringify method. This is a useful way to transfer data from JavaScript to CSPro logic if the data cannot be represented by a CSPro object that can be handled by the JS.getValue function.
The string expression name is evaluated and can refer to a variable in CSPro's JavaScript global execution context or an object's property if the object exists globally. For example, the following values can be specified as a name:
  • myFunction
  • globalThis.myFunction
  • myObject.myProperty
  • myObject['my' + 'Property']
Return Value
The function returns a string containing the JSON if the variable or property is defined. If undefined, or if the JavaScript evaluation ends in an uncaught exception, the function returns a blank string and displays an error message. If you do not want to see the error message, check the existence of the variable or property by using the JS.hasValue function.
Example
JS.setValueFromJson("france", ' { "name": "France",        '
                             
'   "capital": "Paris",      '
                             
'   "currency": "Euro",      '
                             
'   "republicNumber": 5,     '
                             
'   "languages": ["French"] }');

JS.getValueJson("france.name");           // "France"
JS.getValueJson("france.republicNumber"); // 5
JS.getValueJson("france.languages[0]");   // "French"
JS.getValueJson("france.languages[1]");   // error: 'france.languages[1]' is not a defined property.
JS.getValueJson("france.languages");      // ["French"]
See also: JavaScript Use in CSPro, JS Namespace, JS.getValue Function, JS.hasValue Function, JS.setValueFromJson Function