public static void removePath(IStructuredDocument document, IJSONPath path) {
   IJSONModel model = null;
   try {
     model = (IJSONModel) StructuredModelManager.getModelManager().getModelForRead(document);
     IJSONPair pair = findByPath(model.getDocument(), path.getSegments());
     if (pair != null) {
       document.replaceText(
           document, pair.getStartOffset(), pair.getEndOffset() - pair.getStartOffset(), "");
     }
   } finally {
     if (model != null) {
       model.releaseFromRead();
     }
   }
 }
  private static int getEndOffset(IJSONNode parent, boolean inside) {
    if (parent == null) {
      return 0;
    }
    switch (parent.getNodeType()) {
      case IJSONNode.OBJECT_NODE:
        if (parent.hasChildNodes()) {
          IJSONNode lastChild = parent.getLastChild();
          boolean childInside =
              inside
                  && (isSimpleValue(lastChild)
                      || (lastChild.getNodeType() == IJSONNode.PAIR_NODE
                          && isSimpleValue(((IJSONPair) lastChild).getValue())));
          return getEndOffset(lastChild, childInside);
        }
        return parent.getStartOffset() + (inside ? 1 : 0);
      case IJSONNode.PAIR_NODE:
        if (!inside) {
          return parent.getEndOffset();
        }

        IJSONPair pair = (IJSONPair) parent;
        IJSONValue value = (IJSONValue) pair.getValue();
        if (value != null) {
          return getEndOffset(value, false);
        }
        return pair.getEndOffset();
      case IJSONNode.VALUE_BOOLEAN_NODE:
      case IJSONNode.VALUE_NULL_NODE:
      case IJSONNode.VALUE_NUMBER_NODE:
      case IJSONNode.VALUE_STRING_NODE:
        return parent.getStartOffset()
            + parent.getFirstStructuredDocumentRegion().getFirstRegion().getLength();
      default:
        return parent.getEndOffset();
    }
  }