10.3.35 getJsonValue (gets a value corresponding to the name of JSON data)
Syntax
getJsonValue [-e character-encoding] name [file-path-name]
Description
This command searches for element name from the XML file specified for argument and outputs values for all fully matched names.
Arguments
- -e character-encoding
-
- Windows edition
-
Specifies the character encoding for JSON file. "SJIS" or "UTF8" can be specified. If you do not specify this option, the character encoding is treated as UTF8.
- UNIX edition
-
This command specifies the character encoding for JSON file in the format of value of the environment variable LANG. For values that can be specified, see 2.2.4 Encoding used in JP1/Advanced Shell.
If you do not specify this option, assume that the character encoding is specified in the format of the value of the LANG environment variable in the environment where JP1/Advanced Shell operates.
For example, if the JSON file with the character encoding UTF-8 in AIX is treated, specify "JA_JP" or "JA_JP.UTF-8" for -e option.
- name
-
This command specifies the name to be searched.
- file-path-name
-
This command specifies the path of JSON file. If you do not specify the file path name, input from the standard input.
Output to the standard output
Value that corresponds to JSON data.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
Not less than 1 |
Termination with an error |
Notes
-
If matching name is not found, the command terminates with an error.
-
If the data having the same name is nested, output the value corresponding to the outermost name of data.
Examples: (test.json) : {"num":{"id":"0001","num":200}}
If the aforementioned data is searched by using num, {"id":"0001","num":200} is output. In this case, the value (200) corresponding to the inner name of the data can be output by specifying the following:
getJsonValue num test.json | getJsonValue num
-
This part creates a temporary file by using the adshmktemp command. Therefore, the temporary file might remain when the command receives a forced termination request while the part is being executed. In this case, delete the temporary file manually. Temporary file is created in the directory defined with the TEMP_FILE_DIR parameter of the temporary file according to the following naming rule:
getJsonValue_job-ID_process-ID_time-information_file-sequence-number
Examples
JSON data (data.json) { "city": [ { "name":"Yokohama", "id":"0001", "value":{ "A":200, "B":100 } }, { "name":"Kawasaki", "id":"0002", "value":{ "A":100, "B":300 } } ] } getJsonValue name data.json # The following contents are output: "Yokohama" "Kawasaki" getJsonValue -e SJIS value data.json # The following contents are output: { "A":200, "B":100 } { "A":100, "B":300 }