Skip to content

A simple way to read data from JSON by specifying path expressions. Written in Salesforce Apex

License

Notifications You must be signed in to change notification settings

aidan-harding/apex-json-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Reader

Read values from JSON by specifying simple paths like 'a.b' or 'a.b[2].c'.

Examples

Basic usage:

String jsonString = '{"a": { "a2": "expected"} }';

Object result = new JsonReader(jsonString).read('a.a2');

System.assertEquals('expected', result);

With lists:

String jsonString = '{"a": { "a2": ["x", ["expected"]] } }';

Object result = new JsonReader(jsonString).read('a.a2[1][0]');

System.assertEquals('expected', result);

Specifying behaviour for missing keys:

String jsonString = '{"a": { "a2": "expected"} }';
final String NO_RESULT = 'no result';

Object result = new JsonReader(jsonString)
        .setMissingKeyResult(NO_RESULT)
        .read('a.nope');

System.assertEquals(NO_RESULT, result);

License

MIT, see LICENSE

About

A simple way to read data from JSON by specifying path expressions. Written in Salesforce Apex

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages