Skip to content

Commit

Permalink
fix: Solve json path issue for string numerals #2792
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Jul 17, 2024
1 parent 192d152 commit 761e9b4
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@ List<String> getTextsFromCredential(
) {
final textList = <String>[];
try {
final fieldsPath = JsonPath(jsonPath.replaceAll(RegExp(r'\.vc(?=\.)'), ''));
/// finds all occurrences of a dot followed by one or more digits
/// in the jsonPath string
final numericStringFinderRegex = RegExp(r'\.(\d+)');

var updatedJsonPath =
jsonPath.replaceAllMapped(numericStringFinderRegex, (match) {
final key = match.group(1);

///e.g. $.age_equal_or_over.18 becomes $.age_equal_or_over['18']
return "['$key']";
});

/// matches the string .vc only if it is immediately followed by another dot
/// matches: .vc. , ab.vc.
/// doesnot match: .vca.asd
final vcFinderRegex = RegExp(r'\.vc(?=\.)');
updatedJsonPath = updatedJsonPath.replaceAll(vcFinderRegex, '');

final fieldsPath = JsonPath(updatedJsonPath);

fieldsPath.read(data).forEach((a) {
final dynamic value = a.value;
if (value is String) {
Expand Down

0 comments on commit 761e9b4

Please sign in to comment.