cswork / OAOpen practice workspace

AdobeOA #3

Get Nested Dictionary Value by Dotted Path

Estimated EasyJudge-ready

Topics (AI-labelled)StringsHashing

Split the path on dots and access the dictionary one key at a time, level by level. If a key is missing or an intermediate value is not an object, return null; arrays are not accessed by index. Any JSON value found is returned as is, and null is not the string "null".

Input

The input has two lines: a JSON object and a JSON string path. The path is non-empty with a length of ≤200 code points, and an empty segment looks up the empty key. at most 5000 tree nodes, depth ≤30, each key and string ≤200 code points, and all keys/strings together ≤250000 code points. Values are complete JSON scalars/arrays/objects, keys are strings of Unicode scalars, and duplicate keys are invalid. Numbers are finite, each token is ≤64 characters, the absolute value of the exponent is ≤12, the absolute value is ≤10^9, and every number lies exactly on the 10^-6 grid. The total input size is ≤4MiB.

Output

Output one line of canonical ASCII JSON: object keys are sorted by ascending Unicode code point, with no extra whitespace; strings use ASCII JSON escapes (non-BMP characters as lowercase four-digit surrogate pairs); numbers use no exponent, trailing zeros in the fraction and a redundant decimal point are removed, and −0 becomes 0; true/false/null are lowercase. Spaces inside strings must be preserved. The unique string escaping is equivalent to Python json.dumps(value, ensure_ascii=True): printable ASCII other than the double quote and backslash is kept as is (including /), and those two are escaped with a backslash; backspace, form feed, newline, carriage return and tab use short escapes, and all other control characters as well as DEL/non-ASCII use lowercase four-digit Unicode escapes, with non-BMP characters as surrogate pairs.

Example 1

Input:

{"car":{"wheels":2,"gears":5}}
"car.gears"

Output:

5

Example 2

Input:

{"car":{"gears":5}}
"car.color"

Output:

null

Example 3

Input:

{"a":{"z":1.250000,"b":true,"n":null}}
"a"

Output:

{"b":true,"n":null,"z":1.25}

Example notes

The outputs of the three public examples are, in order: 5; null; {"b":true,"n":null,"z":1.25}. Verified by independent enumeration or direct simulation.

Editorial

Loading solution…