1

I'm trying to figure out shortest and effective path to parse values from json and store some of them into chronicle map.

My current solution:

String data = ...;
ChronicleMap<CharSequence, Long> map = ...;
JSONWire wire = new JSONWire(Bytes.allocateElasticDirect(128));
wire.bytes().append(data);
long value = wire.read("fieldName").readLong();
map.put("key", value);

Can I escape somehow reading to long and save bytes to map, assuming that this is long?

1 Answers1

0

If you are looking for the first occurrence of the field name and want the value after it, I would parse it manually. JSOWire assumes you want to read the whole message.

String field = "\"fieldName\":";
int pos = data.indexOf(field);
if (pos >= 0) {
   int end = data.indexOf(",", pos + field.length());
   long value = Long.parseLong(data.substring(pos + field.length(), end));
   // use the value
}
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130